Views
No views yet
1import torch
2import torch.nn as nn
3from huggingface_hub import hf_hub_download
4
5class LinearModel(nn.Module):
6 def __init__(self, input_size, output_size, bias=False):
7 super(LinearModel, self).__init__()
8 self.fc = nn.Linear(input_size, output_size, bias=bias)
9 def forward(self, x):
10 output = self.fc(x)
11 return output
12
13# example: llama-2-7b probe at layer 0, predicting 3 tokens ago
14# predicting the next token would be `layer0_tgtidx1.ckpt`
15checkpoint_path = hf_hub_download(
16 repo_id="sfeucht/footprints",
17 filename="llama-2-7b/layer0_tgtidx-3.ckpt"
18)
19
20# model_size is 4096 for both models.
21# vocab_size is 32000 for Llama-2-7b and 128256 for Llama-3-8b
22probe = LinearModel(4096, 32000).cuda()
23probe.load_state_dict(torch.load(checkpoint_path))