Build the Sinusoidal Position Table
Implement sinusoidal_positional_encoding(seq_len, d_model) that returns a tinygrad Tensor of shape (seq_len, d_model) with the standard transformer recipe:
- Even columns (2i): PEp,2i=sin(p/100002i/dmodel).
- Odd columns (2i+1): PEp,2i+1=cos(p/100002i/dmodel).
You may assume d_model is even.
Hints
Tensor.arange(N) produces [0,1,…,N−1]. Cast to float for arithmetic.
- Compute the inverse frequency in log space to avoid overflow:
exp(-log(10000) * 2i / d_model).
- Outer product (column-vec * row-vec) gives the angle matrix of shape
(seq_len, d_model // 2).
- For interleaving sin and cos: unsqueeze each to
(seq_len, half, 1), cat along the last axis, then reshape to (seq_len, d_model).