Compare commits

...

12 Commits

Author SHA1 Message Date
askerlee
db504bae94
Merge 8cfa0451f4 into 0aaca56805 2026-04-20 12:37:15 +00:00
Andrej
0aaca56805
Merge pull request #706 from svlandeg/fix/cpu
Add setuptools for CPU run
2026-04-14 11:33:14 -07:00
Andrej
b9b6ce137b
Merge pull request #686 from marcinbogdanski/fix/init-smear-backout-lambdas
Initialize smear and backout lambdas in init_weights()
2026-04-13 16:08:04 -07:00
Sofie Van Landeghem
a3ca42a678
add comment 2026-04-13 14:17:23 +02:00
Sofie Van Landeghem
9822cc7424
use nn.init and initialize smear gate's weight as well 2026-04-13 14:03:18 +02:00
svlandeg
12839c11e3 update uv lock 2026-04-13 11:20:38 +02:00
svlandeg
8ef90bc154 add setuptools for CPU run 2026-04-13 10:50:57 +02:00
Marcin Bogdanski
94b73ad29a fix: initialize smear and backout lambdas in init_weights 2026-04-03 20:39:55 +00:00
askerlee
8cfa0451f4 When eval language_modeling tasks, be case insensitive to answers 2026-01-14 15:47:36 +08:00
askerlee
e64aa82620 When evaluating language_modeling tasks, be case-insensitive when matching with the correct answer 2026-01-14 15:34:40 +08:00
askerlee
bf067e2a66 Add max_seq_len argument for gpt2 2026-01-14 14:19:20 +08:00
askerlee
d6829284c4 Allow local install and model loading 2026-01-13 22:20:22 +08:00
5 changed files with 17 additions and 1 deletions

1
.gitignore vendored
View File

@ -11,3 +11,4 @@ eval_bundle/
# Local setup
CLAUDE.md
wandb/
*.egg-info/

View File

@ -201,6 +201,9 @@ def evaluate_example(idx, model, tokenizer, data, device, task_meta):
for t, s, e in zip(tokens, start_idxs, end_idxs):
if len(t) > max_tokens:
num_to_crop = len(t) - max_tokens
# Take the last max_tokens tokens instead of the first ones.
# The overly long questions are usually the few-shot contexts. They are placed
# at the beginning of the sequence, so cropping from the start should be ok.
new_tokens.append(t[-max_tokens:]) # take the last max_tokens tokens
new_start_idxs.append(s - num_to_crop) # shift the indices down
new_end_idxs.append(e - num_to_crop)
@ -228,7 +231,11 @@ def evaluate_example(idx, model, tokenizer, data, device, task_meta):
# predictions[i] predict input_ids[i+1] autoregressively
predicted_tokens = predictions[0, si-1:ei-1]
actual_tokens = input_ids[0, si:ei]
is_correct = torch.all(predicted_tokens == actual_tokens).item()
# Make the matching case-insensitive for LM tasks
predicted_text = tokenizer.decode(predicted_tokens.cpu().tolist()).lower()
actual_text = tokenizer.decode(actual_tokens.cpu().tolist()).lower()
# is_correct = torch.all(predicted_tokens == actual_tokens).item()
is_correct = (predicted_text == actual_text)
elif task_type in ['multiple_choice', 'schema']:
# For MC/schema: find the option with lowest average loss
mean_losses = [losses[i, si-1:ei-1].mean().item()

View File

@ -238,6 +238,11 @@ class GPT(nn.Module):
for i in range(n_layer):
self.x0_lambdas.data[i] = 0.20 - (0.15 * i / max(n_layer - 1, 1))
# Smear/backout scalars and smear gate must be explicitly initialized
torch.nn.init.zeros_(self.smear_lambda)
torch.nn.init.constant_(self.backout_lambda, 0.2)
torch.nn.init.uniform_(self.smear_gate.weight, 0.0, 0.02)
# Value embeddings (init like c_v: uniform with same std)
for ve in self.value_embeds.values():
torch.nn.init.uniform_(ve.weight, -s, s)

View File

@ -54,6 +54,7 @@ explicit = true
[project.optional-dependencies]
cpu = [
"setuptools>=65.0.0",
"torch==2.9.1",
]
gpu = [

View File

@ -1507,6 +1507,7 @@ dependencies = [
[package.optional-dependencies]
cpu = [
{ name = "setuptools" },
{ name = "torch", version = "2.9.1", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "(sys_platform == 'darwin' and extra == 'extra-8-nanochat-cpu') or (extra == 'extra-8-nanochat-cpu' and extra == 'extra-8-nanochat-gpu')" },
{ name = "torch", version = "2.9.1+cpu", source = { registry = "https://download.pytorch.org/whl/cpu" }, marker = "(sys_platform != 'darwin' and extra == 'extra-8-nanochat-cpu') or (extra == 'extra-8-nanochat-cpu' and extra == 'extra-8-nanochat-gpu')" },
]
@ -1530,6 +1531,7 @@ requires-dist = [
{ name = "kernels", specifier = ">=0.11.7" },
{ name = "psutil", specifier = ">=7.1.0" },
{ name = "rustbpe", specifier = ">=0.1.0" },
{ name = "setuptools", marker = "extra == 'cpu'", specifier = ">=65.0.0" },
{ name = "tiktoken", specifier = ">=0.11.0" },
{ name = "tokenizers", specifier = ">=0.22.0" },
{ name = "torch", specifier = "==2.9.1" },