Views
No views yet
uv by following https://docs.astral.sh/uv/getting-started/installation1uv venv ~/.uv-hf --python 3.13
2source ~/.uv-hf/bin/activate
3uv pip install transformers==4.56.2 'trl[vllm]==0.23.1' tensorboard
4uv pip install --pre --index-url https://download.pytorch.org/whl/nightly/cu126 torchaongpu, device_batch_size, grad_accum_steps, and lr variables below to fit your setup.1source ~/.uv-hf/bin/activate
2[ ! -f "qat_sft.py" ] || hf download pytorch/parq-sft --repo-type dataset --local-dir .
3
4SEED=$RANDOM
5SAVE_DIR=checkpoints/qwen3-2bit-fineweb-${SEED}
6
7ngpu=8
8device_batch_size=4
9grad_accum_steps=2
10lr=4.5e-5
11TRANSFORMERS_VERBOSITY=error TOKENIZERS_PARALLELISM=$(( ngpu == 1 )) \
12 PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True HF_HUB_DISABLE_XET=1 \
13 torchrun \
14 --nproc-per-node $ngpu \
15 --rdzv-endpoint localhost:$(shuf -i 29000-29500 -n 1) \
16 -m qat_sft \
17 --model_name_or_path Qwen/Qwen3-4B \
18 --bf16 true \
19 --num_train_epochs 1 \
20 --per_device_train_batch_size $device_batch_size \
21 --gradient_accumulation_steps $grad_accum_steps \
22 --dataset_name HuggingFaceFW/fineweb-edu \
23 --dataset_train_split "train[:10%]" \
24 --dataloader_num_workers 4 \
25 --max_length 8192 \
26 --save_total_limit 1 \
27 --report_to tensorboard \
28 --logging_steps 2 \
29 --learning_rate $lr \
30 --lr_scheduler_type linear \
31 --warmup_ratio 0.0 \
32 --seed $SEED \
33 --output_dir $SAVE_DIR \
34 --enable_thinking \
35 --weight_bits 2 \
36 --linear_pat 'proj\.weight$' \
37 --embed_bits 4 \
38 --embed_pat '(lm_head|embed_tokens)'push_to_hub you need to run1pip install -U "huggingface_hub[cli]"
2huggingface-cli login1import os
2
3from huggingface_hub import whoami, get_token
4from transformers import AutoModelForCausalLM, AutoTokenizer
5
6model_path = f"{SAVE_DIR}"
7model = AutoModelForCausalLM.from_pretrained(
8 model_path, device_map="auto", dtype="auto"
9)
10tokenizer = AutoTokenizer.from_pretrained(model_path)
11
12# Manual testing
13prompt = "Hey, are you conscious? Can you talk to me?"
14messages = [
15 {"role": "system", "content": ""},
16 {"role": "user", "content": prompt},
17]
18templated_prompt = tokenizer.apply_chat_template(
19 messages,
20 tokenize=False,
21 add_generation_prompt=True,
22)
23inputs = tokenizer(templated_prompt, return_tensors="pt").to(model.device)
24inputs.pop("token_type_ids", None)
25
26start_idx = len(inputs.input_ids[0])
27response_ids = model.generate(**inputs, max_new_tokens=256, **kwargs)[0]
28response_ids = response_ids[start_idx:].tolist()
29output_text = tokenizer.decode(response_ids, skip_special_tokens=True)
30print(output_text)
31
32# Push to hub
33token = get_token()
34username = whoami(token=token)["name"]
35model_name = os.path.basename(model_path)
36save_to = os.path.join(username, model_name)
37model.push_to_hub(save_to, safe_serialization=False)
38tokenizer.push_to_hub(save_to)Yes, I am conscious and can communicate with you. How can I be of service to you?| Benchmark | Qwen3-4B | Qwen3-4B-PARQ |
|---|---|---|
| arc_easy | 80.26 | 73.19 |
| arc_challenge | 53.92 | 47.27 |
| boolq | 85.11 | 69.11 |
| hellaswag | 68.49 | 66.67 |
| piqa | 74.97 | 75.24 |
| winogrande | 65.67 | 65.19 |
1git clone https://github.com/pytorch/executorch.git
2pushd executorch
3git submodule update --init --recursive
4python install_executorch.py
5popd1git clone https://github.com/pytorch/ao.git
2pushd ao
3pip install .
4popdBUILD_TORCHAO_EXPERIMENTAL=1 TORCHAO_BUILD_CPU_AARCH64=1 TORCHAO_BUILD_KLEIDIAI=1 TORCHAO_ENABLE_ARM_NEON_DOT=1 TORCHAO_PARALLEL_BACKEND=OPENMP).python -m executorch.examples.models.qwen3.convert_weights $(hf download lvj/Qwen3-4B-parq-2b-weight-4b-embed-shared) pytorch_model_converted.bin1python -m executorch.examples.models.llama.export_llama \
2 --model "qwen3_4b" \
3 --checkpoint pytorch_model_converted.bin \
4 --params examples/models/qwen3/config/4b_config.json \
5 --output_name model.pte \
6 -kv \
7 --use_sdpa_with_kv_cache \
8 --use-torchao-kernels \
9 --max_context_length 1024 \
10 --max_seq_length 1024 \
11 --dtype fp32 \
12 --metadata '{"get_bos_id":151644, "get_eos_ids":[151643, 151645]}'