MCPcopy Create free account
hub / github.com/RightNow-AI/autokernel / LlamaModel

Class LlamaModel

models/llama_7b.py:115–161  ·  view source on GitHub ↗

Compact LLaMA (160M params) -- fits on any GPU, good for testing AutoKernel. Config: dim=768, n_layers=12, n_heads=12, n_kv_heads=4, hidden_dim=2048

Source from the content-addressed store, hash-verified

113
114
115class LlamaModel(nn.Module):
116 """
117 Compact LLaMA (160M params) -- fits on any GPU, good for testing AutoKernel.
118
119 Config: dim=768, n_layers=12, n_heads=12, n_kv_heads=4, hidden_dim=2048
120 """
121
122 def __init__(
123 self,
124 vocab_size: int = 32000,
125 dim: int = 768,
126 n_layers: int = 12,
127 n_heads: int = 12,
128 n_kv_heads: int = 4,
129 hidden_dim: int = 2048,
130 max_seq_len: int = 2048,
131 ):
132 super().__init__()
133 self.tok_embeddings = nn.Embedding(vocab_size, dim)
134 self.layers = nn.ModuleList([
135 TransformerBlock(dim, n_heads, n_kv_heads, hidden_dim)
136 for _ in range(n_layers)
137 ])
138 self.norm = RMSNorm(dim)
139 self.output = nn.Linear(dim, vocab_size, bias=False)
140
141 # RoPE frequencies
142 self.register_buffer(
143 "freqs_cis",
144 precompute_freqs_cis(dim // n_heads, max_seq_len * 2),
145 persistent=False,
146 )
147
148 n_params = sum(p.numel() for p in self.parameters())
149 print(f"LlamaModel: {n_params / 1e6:.1f}M parameters")
150
151 def forward(self, input_ids: torch.Tensor) -> torch.Tensor:
152 B, T = input_ids.shape
153 h = self.tok_embeddings(input_ids)
154 freqs = self.freqs_cis[:T]
155
156 for layer in self.layers:
157 h = layer(h, freqs)
158
159 h = self.norm(h)
160 logits = self.output(h)
161 return logits
162
163
164class LlamaModel7B(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected