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 torchao--dataset_name with a custom finetuning dataset and remove --dataset_sources.1source ~/.uv-hf/bin/activate
2
3SEED=$RANDOM
4SAVE_DIR=checkpoints/qwen3-4bit-tulu-finetune-${SEED}
5
6ngpu=1
7device_batch_size=4
8grad_accum_steps=8
9lr=2e-5
10PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True \
11 uv run "https://huggingface.co/datasets/pytorch/parq-sft/resolve/main/qat_sft.py" \
12 --model_name_or_path Qwen/Qwen3-4B \
13 --bf16 True \
14 --num_train_epochs 1 \
15 --per_device_train_batch_size $device_batch_size \
16 --gradient_accumulation_steps $grad_accum_steps \
17 --dataset_name allenai/tulu-3-sft-olmo-2-mixture-0225 \
18 --dataset_sources ai2-adapt-dev/tulu_v3.9_open_math_2_gsm8k_50k,allenai/tulu-3-sft-personas-math-grade-filtered \
19 --dataloader_num_workers 4 \
20 --save_steps 1500 \
21 --save_total_limit 1 \
22 --report_to tensorboard \
23 --logging_steps 2 \
24 --learning_rate $lr \
25 --lr_scheduler_type linear \
26 --warmup_ratio 0.0 \
27 --seed $SEED \
28 --output_dir $SAVE_DIR \
29 --enable_thinking \
30 --weight_bits 4 \
31 --linear_pat 'proj\.weight$' \
32 --embed_bits 4 \
33 --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 = "John writes 20 pages a day. How long will it take him to write 3 books that are 400 pages each?"
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)1Let's compute the total number of pages John has to write. There are 3 books, each with 400 pages. So the total number of pages is 3 * 400 = 1200 pages.
2
3John writes 20 pages a day.
4
5So the number of days it will take him to write 1200 pages is 1200 / 20 = 60 days.
6
7Thus, it will take John \boxed{60} days to write 3 books.