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
| set -euo pipefail | |
| if [[ $# -lt 1 || $# -gt 2 ]]; then | |
| echo "Usage: $0 aha|l2a_style [GPU_ID]" >&2 | |
| exit 2 | |
| fi | |
| ARM="$1" | |
| GPU="${2:-0}" | |
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
| RECIPE="$(cd "$SCRIPT_DIR/.." && pwd)" | |
| REPO="$(cd "$RECIPE/.." && pwd)" | |
| VANILLA_DIR="${VANILLA_DIR:-$REPO}" | |
| DATA_DIR="${DATA_DIR:-$RECIPE/data/am_distilled_long_mix}" | |
| OUTPUT_ROOT="${OUTPUT_ROOT:-$REPO/outputs}" | |
| case "$ARM" in | |
| aha) GRANULARITY=token_kv_head ;; | |
| l2a_style) GRANULARITY=token ;; | |
| *) echo "Unknown arm: $ARM (expected aha or l2a_style)" >&2; exit 2 ;; | |
| esac | |
| ARM_OUT="$OUTPUT_ROOT/$ARM" | |
| HOTSTART="$ARM_OUT/hotstart" | |
| STAGE1="$ARM_OUT/stage1" | |
| STAGE2="$ARM_OUT/stage2" | |
| LOG_DIR="$ARM_OUT/logs" | |
| mkdir -p "$LOG_DIR" | |
| export CUDA_VISIBLE_DEVICES="$GPU" | |
| export PYTHONUNBUFFERED=1 | |
| export TOKENIZERS_PARALLELISM=false | |
| export PYTORCH_CUDA_ALLOC_CONF="${PYTORCH_CUDA_ALLOC_CONF:-expandable_segments:True}" | |
| if [[ ! -f "$VANILLA_DIR/model.safetensors" ]]; then | |
| echo "Missing tuned-vanilla checkpoint: $VANILLA_DIR/model.safetensors" >&2 | |
| exit 2 | |
| fi | |
| if [[ ! -f "$HOTSTART/config.json" ]]; then | |
| python "$SCRIPT_DIR/export_tuned_vanilla_aha_hotstart.py" \ | |
| --vanilla-path "$VANILLA_DIR" \ | |
| --output-path "$HOTSTART" \ | |
| --window-size 128 \ | |
| --local-kind sink_recent \ | |
| --gate-init-full-prob 0.90 \ | |
| --router-granularity "$GRANULARITY" \ | |
| 2>&1 | tee "$LOG_DIR/hotstart.log" | |
| fi | |
| if [[ ! -f "$STAGE1/checkpoint-300/config.json" ]]; then | |
| AHA_TRAIN_GATE_HARD_THRESHOLD=0.50 \ | |
| python "$RECIPE/dynamic_duo_train.py" \ | |
| --aha_checkpoint "$HOTSTART" \ | |
| --model_path "$VANILLA_DIR" \ | |
| --output_dir "$STAGE1" \ | |
| --data_source am_distilled \ | |
| --am_dataset_path "$DATA_DIR" \ | |
| --am_dataset_split train \ | |
| --am_label_mode full \ | |
| --max_length 8192 \ | |
| --num_steps 300 \ | |
| --warmup_ratio 0.10 \ | |
| --lr 3e-5 \ | |
| --reg_weight 0.1 \ | |
| --ce_weight 0.0 \ | |
| --batch_size 1 \ | |
| --grad_accum 1 \ | |
| --save_steps 100 \ | |
| --log_steps 10 \ | |
| --seed 42 \ | |
| --dtype bfloat16 \ | |
| --attn_impl sdpa \ | |
| --aha_local_kind sink_recent \ | |
| --router_granularity "$GRANULARITY" \ | |
| 2>&1 | tee "$LOG_DIR/stage1.log" | |
| fi | |
| if [[ ! -f "$STAGE2/checkpoint-75/config.json" ]]; then | |
| MODEL_PATH="$VANILLA_DIR" \ | |
| AHA_CHECKPOINT_PATH="$STAGE1/checkpoint-300" \ | |
| DATASET_PATH="$DATA_DIR" \ | |
| DATASET_SPLIT=train \ | |
| OUTPUT_DIR="$STAGE2" \ | |
| AHA_MODE=dynamic \ | |
| AHA_ROUTER_GRANULARITY="$GRANULARITY" \ | |
| AHA_LOCAL_KIND=sink_recent \ | |
| AHA_CE_WEIGHT=1.0 \ | |
| AHA_DISTILL_WEIGHT=0.5 \ | |
| AHA_REG_WEIGHT=0.01 \ | |
| AHA_TRAIN_GATE_HARD_THRESHOLD=0.58 \ | |
| GROUPED_LR=1 \ | |
| GATE_ONLY=0 \ | |
| LEARNING_RATE=3e-6 \ | |
| GATE_LEARNING_RATE=3e-6 \ | |
| BACKBONE_LEARNING_RATE=3e-7 \ | |
| LR_SCHEDULER_TYPE=constant_with_warmup \ | |
| WARMUP_RATIO=0.10 \ | |
| WEIGHT_DECAY=0.0 \ | |
| MAX_SEQ_LENGTH=8192 \ | |
| PER_DEVICE_TRAIN_BATCH_SIZE=1 \ | |
| GRADIENT_ACCUMULATION_STEPS=1 \ | |
| MAX_STEPS=75 \ | |
| LOGGING_STEPS=5 \ | |
| SAVE_STEPS=25 \ | |
| SAVE_TOTAL_LIMIT=3 \ | |
| FREEZE_EMBEDDINGS_LM_HEAD=1 \ | |
| REPORT_TO=none \ | |
| SEED=47 \ | |
| python "$RECIPE/sft.py" \ | |
| 2>&1 | tee "$LOG_DIR/stage2.log" | |
| fi | |
| python - "$STAGE2/checkpoint-25" "$GRANULARITY" <<'PY' | |
| import json | |
| import sys | |
| from pathlib import Path | |
| checkpoint = Path(sys.argv[1]) | |
| expected = sys.argv[2] | |
| config = json.loads((checkpoint / "config.json").read_text()) | |
| actual = config.get("aha_router_granularity", "token_kv_head") | |
| if actual != expected: | |
| raise RuntimeError(f"checkpoint granularity {actual!r} != {expected!r}") | |
| print(f"selected_checkpoint={checkpoint} router_granularity={actual}") | |
| PY | |