Text Generation
Transformers
Safetensors
English
qwen3
long-context
sparse-attention
aha
l2a-style
reproducibility
conversational
text-generation-inference
Instructions to use keepsloading/icml_repro_scratch with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use keepsloading/icml_repro_scratch with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="keepsloading/icml_repro_scratch") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("keepsloading/icml_repro_scratch") model = AutoModelForCausalLM.from_pretrained("keepsloading/icml_repro_scratch", 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use keepsloading/icml_repro_scratch with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "keepsloading/icml_repro_scratch" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "keepsloading/icml_repro_scratch", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/keepsloading/icml_repro_scratch
- SGLang
How to use keepsloading/icml_repro_scratch 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 "keepsloading/icml_repro_scratch" \ --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": "keepsloading/icml_repro_scratch", "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 "keepsloading/icml_repro_scratch" \ --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": "keepsloading/icml_repro_scratch", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use keepsloading/icml_repro_scratch with Docker Model Runner:
docker model run hf.co/keepsloading/icml_repro_scratch
File size: 2,685 Bytes
46b9eea | 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 | """Shared training helpers for AHA q_proj router rows."""
from __future__ import annotations
from dataclasses import dataclass
import torch
from modeling_aha_qwen3 import aha_router_output_size
@dataclass
class GateOnlySetup:
parameters: list[torch.nn.Parameter]
effective_parameter_count: int
q_rows: int
gate_rows: int
class RowWiseAdamW(torch.optim.AdamW):
"""AdamW with an exact lower LR on prefixes of selected tensors."""
def __init__(self, params, *, row_scales, **kwargs):
super().__init__(params, **kwargs)
self._row_scales = row_scales
@torch.no_grad()
def step(self, closure=None):
before = [p[:n_rows].detach().clone() for p, n_rows, _ in self._row_scales]
loss = super().step(closure=closure)
for (parameter, n_rows, scale), old in zip(self._row_scales, before):
if scale != 1.0:
new = parameter[:n_rows]
new.copy_(old + scale * (new - old))
return loss
def q_projection_rows(config) -> int:
head_dim = getattr(
config,
"head_dim",
config.hidden_size // config.num_attention_heads,
)
return int(config.num_attention_heads * head_dim)
def configure_gate_only(model: torch.nn.Module) -> GateOnlySetup:
"""Freeze a model and expose only the appended q_proj gate rows.
PyTorch cannot mark only a slice of a Parameter trainable, so each q_proj
tensor remains trainable while a hook zeros the ordinary Q-row gradient.
The returned parameter count is the effective native gate parameter count,
not the full q_proj tensor size seen by the optimizer.
"""
for parameter in model.parameters():
parameter.requires_grad = False
q_rows = q_projection_rows(model.config)
gate_rows = aha_router_output_size(model.config)
def mask_q_rows(gradient: torch.Tensor) -> torch.Tensor:
masked = gradient.clone()
masked[:q_rows] = 0.0
return masked
parameters: list[torch.nn.Parameter] = []
effective = 0
for layer in model.model.layers:
q_proj = layer.self_attn.q_proj
q_proj.weight.requires_grad = True
q_proj.weight.register_hook(mask_q_rows)
parameters.append(q_proj.weight)
effective += gate_rows * q_proj.in_features
if q_proj.bias is not None:
q_proj.bias.requires_grad = True
q_proj.bias.register_hook(mask_q_rows)
parameters.append(q_proj.bias)
effective += gate_rows
return GateOnlySetup(
parameters=parameters,
effective_parameter_count=effective,
q_rows=q_rows,
gate_rows=gate_rows,
)
|