MCPcopy
hub / github.com/tinygrad/tinygrad / precompute_freqs_cis

Function precompute_freqs_cis

tinygrad/llm/model.py:9–12  ·  view source on GitHub ↗
(dim: int, end: int, theta: float = 10000.0, device:str|None=None)

Source from the content-addressed store, hash-verified

7
8@functools.cache
9def precompute_freqs_cis(dim: int, end: int, theta: float = 10000.0, device:str|None=None) -> Tensor:
10 freqs = 1.0 / (theta ** (Tensor.arange(0, dim, 2, device=device)[:(dim // 2)] / dim))
11 freqs = Tensor.arange(end, device=device).unsqueeze(dim=1) * freqs.unsqueeze(dim=0)
12 return freqs.cos().cat(freqs.sin(), dim=-1).contiguous()
13
14class ExpertWeights:
15 """Like nn.Linear but with num_experts dimension. Weight shape: (num_experts, out_features, in_features)."""

Callers 6

apply_ropeFunction · 0.90
apply_ropeFunction · 0.90
_init_stateMethod · 0.70
_init_stateMethod · 0.70

Calls 6

arangeMethod · 0.80
unsqueezeMethod · 0.80
catMethod · 0.80
cosMethod · 0.80
sinMethod · 0.80
contiguousMethod · 0.45

Tested by 4

apply_ropeFunction · 0.72
apply_ropeFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…