Instructions to use Qwen/Qwen3-235B-A22B-Instruct-2507 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Qwen/Qwen3-235B-A22B-Instruct-2507 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Qwen/Qwen3-235B-A22B-Instruct-2507") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen3-235B-A22B-Instruct-2507") model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen3-235B-A22B-Instruct-2507") 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]:])) - Inference
- HuggingChat
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Qwen/Qwen3-235B-A22B-Instruct-2507 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Qwen/Qwen3-235B-A22B-Instruct-2507" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Qwen/Qwen3-235B-A22B-Instruct-2507", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Qwen/Qwen3-235B-A22B-Instruct-2507
- SGLang
How to use Qwen/Qwen3-235B-A22B-Instruct-2507 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 "Qwen/Qwen3-235B-A22B-Instruct-2507" \ --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": "Qwen/Qwen3-235B-A22B-Instruct-2507", "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 "Qwen/Qwen3-235B-A22B-Instruct-2507" \ --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": "Qwen/Qwen3-235B-A22B-Instruct-2507", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Qwen/Qwen3-235B-A22B-Instruct-2507 with Docker Model Runner:
docker model run hf.co/Qwen/Qwen3-235B-A22B-Instruct-2507
π[Fine-tuning] 8x80GiB GPUs LoRA finetuning Qwen3-235B-A22B-Instruct-2507
https://github.com/modelscope/ms-swift/pull/5033
Model Finetuning
We introduce self-cognition finetuning of Qwen3-235B-A22B-Instruct-2507 using Megatron & LoRA integrated with ms-swift. You will need 8 GPUs with 80GiB memory each.
Before starting the finetuning process, please ensure your environment is properly set up.
For instructions on installing Megatron-related dependencies, please refer to the Megatron-SWIFT training documentation (Docker images are also available):
https://swift.readthedocs.io/en/latest/Instruction/Megatron-SWIFT-Training.html
git clone https://github.com/modelscope/ms-swift.git
cd ms-swift
pip install -e .
The finetuning dataset should be prepared in the following format (the "system" field is optional). You can specify it in the training script using --dataset <dataset_path>.
{"messages": [{"role": "user", "content": "Where is the capital of Zhejiang?"}, {"role": "assistant", "content": "The capital of Zhejiang is Hangzhou."}]}
- Convert HF-format weights to Megatron format and test the conversion accuracy:
# 8 * 80GiB
# To test the conversion accuracy, please set --test_convert_precision true. Note that this requires 1.3T of memory resources.
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
swift export \
--model Qwen/Qwen3-235B-A22B-Instruct-2507 \
--to_mcore true \
--torch_dtype bfloat16 \
--output_dir Qwen3-235B-A22B-Instruct-2507-mcore
- Self-cognition finetuning (full-parameter training) of Qwen3-235B-A22B-Instruct-2507-mcore requires 8 H20 GPUs with 90GiB memory each, and achieves a training speed of 3.5 seconds per iteration.
# Memory usage: 8 x 90GiB
# Training speed: 3.5s/it
PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
NPROC_PER_NODE=8 \
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
megatron sft \
--load Qwen3-235B-A22B-Instruct-2507-mcore \
--dataset 'swift/Chinese-Qwen3-235B-2507-Distill-data-110k-SFT#2000' \
'swift/self-cognition#1000' \
--train_type lora \
--lora_rank 8 \
--lora_alpha 32 \
--target_modules all-linear \
--split_dataset_ratio 0.01 \
--expert_model_parallel_size 8 \
--moe_grouped_gemm true \
--moe_shared_expert_overlap true \
--moe_aux_loss_coeff 1e-3 \
--micro_batch_size 2 \
--global_batch_size 16 \
--recompute_granularity full \
--recompute_method uniform \
--recompute_num_layers 1 \
--max_epochs 1 \
--finetune true \
--cross_entropy_loss_fusion true \
--lr 1e-4 \
--lr_warmup_fraction 0.05 \
--min_lr 1e-5 \
--save megatron_output/Qwen3-235B-A22B-Instruct-2507 \
--eval_interval 200 \
--save_interval 200 \
--max_length 2048 \
--num_workers 8 \
--dataset_num_proc 8 \
--no_save_optim true \
--no_save_rng true \
--sequence_parallel true \
--attention_backend flash \
--model_author swift \
--model_name swift-robot
Training memory usage:
Training log:
If you need to run it on 8 GPUs with 80GiB memory each, you can use the following configuration:
# Memory usage: 8 * 78GiB
# Training speed: 9.5s/it
PYTORCH_CUDA_ALLOC_CONF='expandable_segments:True' \
NPROC_PER_NODE=8 \
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
megatron sft \
--load Qwen3-235B-A22B-Instruct-2507-mcore \
--dataset 'swift/Chinese-Qwen3-235B-2507-Distill-data-110k-SFT#2000' \
'swift/self-cognition#1000' \
--optimizer_cpu_offload true \
--use_precision_aware_optimizer true \
--train_type lora \
--lora_rank 8 \
--lora_alpha 32 \
--target_modules all-linear \
--split_dataset_ratio 0.01 \
--expert_model_parallel_size 2 \
--pipeline_model_parallel_size 4 \
--decoder_first_pipeline_num_layers 23 \
--decoder_last_pipeline_num_layers 23 \
--moe_grouped_gemm true \
--moe_shared_expert_overlap true \
--moe_aux_loss_coeff 1e-3 \
--micro_batch_size 8 \
--global_batch_size 16 \
--recompute_granularity full \
--recompute_method uniform \
--recompute_num_layers 1 \
--max_epochs 1 \
--finetune true \
--cross_entropy_loss_fusion true \
--lr 1e-4 \
--lr_warmup_fraction 0.05 \
--min_lr 1e-5 \
--save megatron_output/Qwen3-235B-A22B-Instruct-2507 \
--eval_interval 200 \
--save_interval 200 \
--max_length 2048 \
--num_workers 8 \
--dataset_num_proc 8 \
--no_save_optim true \
--no_save_rng true \
--sequence_parallel true \
--attention_backend flash \
--model_author swift \
--model_name swift-robot
- Convert Megatron-format weights to HF format and test the conversion accuracy:
# 8 * 80GiB
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
swift export \
--mcore_adapters megatron_output/Qwen3-235B-A22B-Instruct-2507/vx-xxx \
--to_hf true \
--torch_dtype bfloat16 \
--output_dir megatron_output/Qwen3-235B-A22B-Instruct-2507/vx-xxx-hf
- After training is completed, use the following command for inference:
# 8 * 80GiB
CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 \
swift infer \
--model output/vx-xxx/checkpoint-xxx \
--infer_backend vllm \
--stream true \
--temperature 0 \
--vllm_tensor_parallel_size 8 \
--vllm_max_model_len 8192 \
--max_new_tokens 2048
- Push the model to ModelScope:
swift export \
--model output/vx-xxx/checkpoint-xxx \
--push_to_hub true \
--hub_model_id '<your-model-id>' \
--hub_token '<your-sdk-token>'
is it possible to use 4*96GB gpus to finetune this model? maybe we can enable fp8 or use qlora?