Instructions to use mrtineu/thinkingcap-test-submission with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mrtineu/thinkingcap-test-submission with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mrtineu/thinkingcap-test-submission") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("mrtineu/thinkingcap-test-submission") model = AutoModelForCausalLM.from_pretrained("mrtineu/thinkingcap-test-submission", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use mrtineu/thinkingcap-test-submission with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mrtineu/thinkingcap-test-submission" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mrtineu/thinkingcap-test-submission", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/mrtineu/thinkingcap-test-submission
- SGLang
How to use mrtineu/thinkingcap-test-submission with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "mrtineu/thinkingcap-test-submission" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mrtineu/thinkingcap-test-submission", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "mrtineu/thinkingcap-test-submission" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mrtineu/thinkingcap-test-submission", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use mrtineu/thinkingcap-test-submission with Docker Model Runner:
docker model run hf.co/mrtineu/thinkingcap-test-submission
File size: 6,777 Bytes
6361ca2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | """CPU tests for arms.py on a tiny random 28-layer Qwen3 (needs torch + transformers, no GPU, no download).
python -m unittest thinkingcap/test_arms.py
TC_ARMS_MODEL=/path/to/Qwen3-0.6B-snapshot runs the same checks on the real model as well.
"""
import json
import os
import sys
import tempfile
import unittest
from pathlib import Path
import torch
sys.path.insert(0, str(Path(__file__).resolve().parent))
import arms # noqa: E402
ARMS = json.loads((Path(__file__).resolve().parent / 'arms.json').read_text())['arms']
def tiny_base(directory):
from transformers import Qwen3Config, Qwen3ForCausalLM
torch.manual_seed(0)
config = Qwen3Config(vocab_size=320, hidden_size=64, intermediate_size=128, num_hidden_layers=28,
num_attention_heads=4, num_key_value_heads=2, head_dim=16, tie_word_embeddings=True,
max_position_embeddings=256, dtype='bfloat16')
Qwen3ForCausalLM(config).to(torch.bfloat16).save_pretrained(directory)
return directory
class Arms(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.tmp = tempfile.TemporaryDirectory()
cls.base_dir = os.environ.get('TC_ARMS_MODEL') or tiny_base(Path(cls.tmp.name) / 'base')
vocab = json.loads((Path(cls.base_dir) / 'config.json').read_text())['vocab_size']
generator = torch.Generator().manual_seed(1)
cls.ids = torch.randint(0, min(vocab, 5000), (2, 48), generator=generator)
@classmethod
def tearDownClass(cls):
cls.tmp.cleanup()
def load(self):
from transformers import AutoModelForCausalLM
return AutoModelForCausalLM.from_pretrained(self.base_dir, dtype=torch.bfloat16).eval()
def logits(self, model):
with torch.no_grad():
return model(input_ids=self.ids).logits
def test_step0_is_base_model(self):
reference = self.logits(self.load())
for name, spec in ARMS.items():
with self.subTest(arm=name):
model = self.load()
trainable = arms.build(spec, model)
self.assertTrue(torch.equal(self.logits(model), reference))
self.assertEqual({p.requires_grad for p in model.parameters() if p.requires_grad}, {True})
self.assertEqual(sum(p.numel() for p in model.parameters() if p.requires_grad),
sum(p.numel() for p in trainable))
def test_trainable_counts_and_numbering(self):
model = self.load()
hidden = model.config.hidden_size
self.assertEqual(sum(p.numel() for p in arms.build(ARMS['mlp-quarters'], model)), 4 * 2 * hidden * 64)
model = self.load()
layer = sum(p.numel() for p in model.model.layers[13].parameters())
self.assertEqual(sum(p.numel() for p in arms.build(ARMS['extra-block'], model)), layer)
self.assertEqual(model.config.num_hidden_layers, 29)
self.assertEqual(len(model.config.layer_types), 29)
self.assertEqual([l.self_attn.layer_idx for l in model.model.layers], list(range(29)))
def test_perturbed_export_roundtrip(self):
reference = self.logits(self.load())
for name, spec in ARMS.items():
with self.subTest(arm=name):
model = self.load()
arms.build(spec, model)
arms.perturb(spec, model, 0)
expected = self.logits(model)
self.assertFalse(torch.equal(expected, reference))
with tempfile.TemporaryDirectory() as out:
arms.export(spec, model, self.base_dir, out)
config = json.loads((Path(out) / 'config.json').read_text())
if spec['kind'] == 'block':
self.assertEqual(config['architectures'], ['Qwen3ForCausalLM'])
self.assertEqual(config['num_hidden_layers'], 29)
else:
self.assertEqual(config['architectures'], [arms.MLP_ARCHITECTURE])
self.assertTrue(torch.equal(self.logits(arms.load_export(out)), expected))
def test_trainable_state_restores(self):
for name, spec in ARMS.items():
with self.subTest(arm=name):
model = self.load()
arms.build(spec, model)
arms.perturb(spec, model, 0)
state = arms.trainable_state(spec, model)
expected = self.logits(model)
fresh = self.load()
arms.build(spec, fresh)
arms.load_trainable_state(fresh, state)
self.assertTrue(torch.equal(self.logits(fresh), expected))
def test_mlp_only_block_trains_only_its_mlp(self):
for name in ('extra-mlp', 'extra-mlp-64'):
with self.subTest(arm=name):
spec = ARMS[name]
model = self.load()
trainable = arms.build(spec, model)
hidden, inter = model.config.hidden_size, model.config.intermediate_size
self.assertEqual(sum(p.numel() for p in trainable), 3 * hidden * inter + hidden)
block = model.model.layers[spec['after'] + 1]
self.assertFalse(any(p.requires_grad for p in block.self_attn.parameters()))
for p in trainable:
p.data = p.data.float()
optimizer = torch.optim.AdamW(trainable, lr=1e-2, weight_decay=0.0)
model.train()
for _ in range(3):
with torch.autocast('cpu', dtype=torch.bfloat16): # as pipeline.fit trains
loss = model(input_ids=self.ids, labels=self.ids).loss
loss.backward()
optimizer.step()
optimizer.zero_grad()
self.assertTrue(torch.equal(block.self_attn.o_proj.weight, torch.zeros_like(block.self_attn.o_proj.weight)))
self.assertGreater(float(block.mlp.down_proj.weight.abs().sum()), 0)
width = spec.get('mlp_width')
if width:
mlp = block.mlp
for dead in (mlp.gate_proj.weight[width:], mlp.up_proj.weight[width:], mlp.down_proj.weight[:, width:]):
self.assertEqual(float(dead.abs().max()), 0.0)
self.assertGreater(float(mlp.gate_proj.weight[:width].abs().sum()), 0)
def test_mlp_names_dodge_vllm_stacked_mapping(self):
model = self.load()
arms.build(ARMS['mlp-quarters'], model)
for name in arms.trainable_state(ARMS['mlp-quarters'], model):
self.assertTrue(all(s not in name for s in ('q_proj', 'k_proj', 'v_proj', 'gate_proj', 'up_proj')), name)
if __name__ == '__main__':
unittest.main()
|