Instructions to use lainlives/Qwen3-Coder-Python-30B-A3B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use lainlives/Qwen3-Coder-Python-30B-A3B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="lainlives/Qwen3-Coder-Python-30B-A3B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("lainlives/Qwen3-Coder-Python-30B-A3B") model = AutoModelForCausalLM.from_pretrained("lainlives/Qwen3-Coder-Python-30B-A3B", 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use lainlives/Qwen3-Coder-Python-30B-A3B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "lainlives/Qwen3-Coder-Python-30B-A3B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "lainlives/Qwen3-Coder-Python-30B-A3B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/lainlives/Qwen3-Coder-Python-30B-A3B
- SGLang
How to use lainlives/Qwen3-Coder-Python-30B-A3B 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 "lainlives/Qwen3-Coder-Python-30B-A3B" \ --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": "lainlives/Qwen3-Coder-Python-30B-A3B", "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 "lainlives/Qwen3-Coder-Python-30B-A3B" \ --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": "lainlives/Qwen3-Coder-Python-30B-A3B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use lainlives/Qwen3-Coder-Python-30B-A3B with Docker Model Runner:
docker model run hf.co/lainlives/Qwen3-Coder-Python-30B-A3B
Commit ·
435d779
0
Parent(s):
Duplicate from burtenshaw/Qwen3-30B-A3B-python-coder
Browse filesCo-authored-by: ben burtenshaw <burtenshaw@users.noreply.huggingface.co>
Files changed (27)
- .gitattributesAdded+36
- README.mdAdded+59
- added_tokens.jsonAdded+28
- config.jsonAdded+38
- generation_config.jsonAdded+13
- merges.txtAdded
- model-00001-of-00013.safetensorsAdded+3
- model-00002-of-00013.safetensorsAdded+3
- model-00003-of-00013.safetensorsAdded+3
- model-00004-of-00013.safetensorsAdded+3
- model-00005-of-00013.safetensorsAdded+3
- model-00006-of-00013.safetensorsAdded+3
- model-00007-of-00013.safetensorsAdded+3
- model-00008-of-00013.safetensorsAdded+3
- model-00009-of-00013.safetensorsAdded+3
- model-00010-of-00013.safetensorsAdded+3
- model-00011-of-00013.safetensorsAdded+3
- model-00012-of-00013.safetensorsAdded+3
- model-00013-of-00013.safetensorsAdded+3
- model.safetensors.index.jsonAdded
- requirements.txtAdded+12
- special_tokens_map.jsonAdded+25
- tokenizer.jsonAdded+3
- tokenizer_config.jsonAdded+240
- train.pyAdded+200
- training_args.binAdded+3
- vocab.jsonAdded
123456789101112131415161718192021222324252627282930313233343536*.7z filter=lfs diff=lfs merge=lfs -text*.arrow filter=lfs diff=lfs merge=lfs -text*.bin filter=lfs diff=lfs merge=lfs -text*.bz2 filter=lfs diff=lfs merge=lfs -text*.ckpt filter=lfs diff=lfs merge=lfs -text*.ftz filter=lfs diff=lfs merge=lfs -text*.gz filter=lfs diff=lfs merge=lfs -text*.h5 filter=lfs diff=lfs merge=lfs -text*.joblib filter=lfs diff=lfs merge=lfs -text*.lfs.* filter=lfs diff=lfs merge=lfs -text*.mlmodel filter=lfs diff=lfs merge=lfs -text*.model filter=lfs diff=lfs merge=lfs -text*.msgpack filter=lfs diff=lfs merge=lfs -text*.npy filter=lfs diff=lfs merge=lfs -text*.npz filter=lfs diff=lfs merge=lfs -text*.onnx filter=lfs diff=lfs merge=lfs -text*.ot filter=lfs diff=lfs merge=lfs -text*.parquet filter=lfs diff=lfs merge=lfs -text*.pb filter=lfs diff=lfs merge=lfs -text*.pickle filter=lfs diff=lfs merge=lfs -text*.pkl filter=lfs diff=lfs merge=lfs -text*.pt filter=lfs diff=lfs merge=lfs -text*.pth filter=lfs diff=lfs merge=lfs -text*.rar filter=lfs diff=lfs merge=lfs -text*.safetensors filter=lfs diff=lfs merge=lfs -textsaved_model/**/* filter=lfs diff=lfs merge=lfs -text*.tar.* filter=lfs diff=lfs merge=lfs -text*.tar filter=lfs diff=lfs merge=lfs -text*.tflite filter=lfs diff=lfs merge=lfs -text*.tgz filter=lfs diff=lfs merge=lfs -text*.wasm filter=lfs diff=lfs merge=lfs -text*.xz filter=lfs diff=lfs merge=lfs -text*.zip filter=lfs diff=lfs merge=lfs -text*.zst filter=lfs diff=lfs merge=lfs -text*tfevents* filter=lfs diff=lfs merge=lfs -texttokenizer.json filter=lfs diff=lfs merge=lfs -text1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859---base_model: Qwen/Qwen3-30B-A3Bdatasets: burtenshaw/tulu-3-sft-personas-code-no-promptlibrary_name: transformersmodel_name: Qwen3-30B-A3B-python-codertags:- generated_from_trainer- trl- sftlicence: license---
# Model Card for Qwen3-30B-A3B-python-coder
This model is a fine-tuned version of [Qwen/Qwen3-30B-A3B](https://huggingface.co/Qwen/Qwen3-30B-A3B) on the [burtenshaw/tulu-3-sft-personas-code-no-prompt](https://huggingface.co/datasets/burtenshaw/tulu-3-sft-personas-code-no-prompt) dataset.It has been trained using [TRL](https://github.com/huggingface/trl).
## Quick start
```pythonfrom transformers import pipeline
question = "If you had a time machine, but could only go to the past or the future once and never return, which would you choose and why?"generator = pipeline("text-generation", model="burtenshaw/Qwen3-30B-A3B-python-coder", device="cuda")output = generator([{"role": "user", "content": question}], max_new_tokens=128, return_full_text=False)[0]print(output["generated_text"])```
## Training procedure
[<img src="https://raw.githubusercontent.com/wandb/assets/main/wandb-github-badge-28.svg" alt="Visualize in Weights & Biases" width="150" height="24"/>](https://wandb.ai/smartwithfood/huggingface/runs/m22i87x1)
This model was trained with SFT.
### Framework versions
- TRL: 0.17.0- Transformers: 4.51.3- Pytorch: 2.7.0- Datasets: 3.5.1- Tokenizers: 0.21.1
## Citations
Cite TRL as: ```bibtex@misc{vonwerra2022trl, title = {{TRL: Transformer Reinforcement Learning}}, author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec}, year = 2020, journal = {GitHub repository}, publisher = {GitHub}, howpublished = {\url{https://github.com/huggingface/trl}}}```12345678910111213141516171819202122232425262728{ "</think>": 151668, "</tool_call>": 151658, "</tool_response>": 151666, "<think>": 151667, "<tool_call>": 151657, "<tool_response>": 151665, "<|box_end|>": 151649, "<|box_start|>": 151648, "<|endoftext|>": 151643, "<|file_sep|>": 151664, "<|fim_middle|>": 151660, "<|fim_pad|>": 151662, "<|fim_prefix|>": 151659, "<|fim_suffix|>": 151661, "<|im_end|>": 151645, "<|im_start|>": 151644, "<|image_pad|>": 151655, "<|object_ref_end|>": 151647, "<|object_ref_start|>": 151646, "<|quad_end|>": 151651, "<|quad_start|>": 151650, "<|repo_name|>": 151663, "<|video_pad|>": 151656, "<|vision_end|>": 151653, "<|vision_pad|>": 151654, "<|vision_start|>": 151652}1234567891011121314151617181920212223242526272829303132333435363738{ "architectures": [ "Qwen3MoeForCausalLM" ], "attention_bias": false, "attention_dropout": 0.0, "bos_token_id": 151643, "decoder_sparse_step": 1, "eos_token_id": 151645, "head_dim": 128, "hidden_act": "silu", "hidden_size": 2048, "initializer_range": 0.02, "intermediate_size": 6144, "max_position_embeddings": 40960, "max_window_layers": 48, "mlp_only_layers": [], "model_type": "qwen3_moe", "moe_intermediate_size": 768, "norm_topk_prob": true, "num_attention_heads": 32, "num_experts": 128, "num_experts_per_tok": 8, "num_hidden_layers": 48, "num_key_value_heads": 4, "output_router_logits": false, "rms_norm_eps": 1e-06, "rope_scaling": null, "rope_theta": 1000000.0, "router_aux_loss_coef": 0.001, "sliding_window": null, "tie_word_embeddings": false, "torch_dtype": "bfloat16", "transformers_version": "4.51.3", "use_cache": false, "use_sliding_window": false, "vocab_size": 151936}12345678910111213{ "bos_token_id": 151643, "do_sample": true, "eos_token_id": [ 151645, 151643 ], "pad_token_id": 151643, "temperature": 0.6, "top_k": 20, "top_p": 0.95, "transformers_version": "4.51.3"}123version https://git-lfs.github.com/spec/v1oid sha256:290d474bdbbc8e52e90494cfd27181cb16520a88fbfade22501777d515ae128dsize 4997184968123version https://git-lfs.github.com/spec/v1oid sha256:608406ced27bda08d0174299b4ceaec6b095b9345a620bf4ff9a31f3b4fa78c8size 4997741608123version https://git-lfs.github.com/spec/v1oid sha256:58dc2604a1c87fb101b4f635c67be710231aa4aea696d2d0336c0fd373318473size 4997742208123version https://git-lfs.github.com/spec/v1oid sha256:3249e9802eed31e05ae80d6da08b6762a7d4405dec45455641ca78e28ddefc5bsize 4997743184123version https://git-lfs.github.com/spec/v1oid sha256:5b1c8f041dabebdfbeb913ac1a456d62c8627534419605e18b0316d895e5bba4size 4997743184123version https://git-lfs.github.com/spec/v1oid sha256:2d09aedef31577d8620411a7575179b0ee3705bce80f77ffff717ca577ff75b9size 4997743184123version https://git-lfs.github.com/spec/v1oid sha256:2a5e0f1e4bef1df995974b35fbcb6a0eddcdb36263c7d81221f1e6dba3ff5e92size 4997743184123version https://git-lfs.github.com/spec/v1oid sha256:79554d2b20f30332817ab44e7fa5d566e38ad630a804ec38f3f4d68c859256c8size 4997743184123version https://git-lfs.github.com/spec/v1oid sha256:e3b271dcb14b65d7711c424366a91b513cb342e57f9ccecc8f18a23852d6927csize 4997743184123version https://git-lfs.github.com/spec/v1oid sha256:815658b4044f4ea9a6dc846d35fbbe44c52fef3f41b9e48dfbb51f7c94560dcfsize 4997743184123version https://git-lfs.github.com/spec/v1oid sha256:0c67a5b0dc8f770ae76b55886679ea84007749a686b9ac7d3cbb7f727fbc5f6bsize 4997743184123version https://git-lfs.github.com/spec/v1oid sha256:392136838244a7f1153a91fbecde66f840c4bdd75a7937104a3e85a5e3e4be37size 4997743184123version https://git-lfs.github.com/spec/v1oid sha256:82e09aa5c14b63281f9d75106a4ff0be14863d328835d78ad099df8a1a88c077size 1094220288123456789101112datasetshttpxhuggingface-hubsetuptoolstransformerstorchacceleratetrlpeftwandbtorchvisiontorchaudio12345678910111213141516171819202122232425{ "additional_special_tokens": [ "<|im_start|>", "<|im_end|>", "<|object_ref_start|>", "<|object_ref_end|>", "<|box_start|>", "<|box_end|>", "<|quad_start|>", "<|quad_end|>", "<|vision_start|>", "<|vision_end|>", "<|vision_pad|>", "<|image_pad|>", "<|video_pad|>" ], "eos_token": "<|im_end|>", "pad_token": { "content": "<|endoftext|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false }}123version https://git-lfs.github.com/spec/v1oid sha256:aeb13307a71acd8fe81861d94ad54ab689df773318809eed3cbe794b4492dae4size 11422654123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240{ "add_bos_token": false, "add_prefix_space": false, "added_tokens_decoder": { "151643": { "content": "<|endoftext|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151644": { "content": "<|im_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151645": { "content": "<|im_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151646": { "content": "<|object_ref_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151647": { "content": "<|object_ref_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151648": { "content": "<|box_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151649": { "content": "<|box_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151650": { "content": "<|quad_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151651": { "content": "<|quad_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151652": { "content": "<|vision_start|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151653": { "content": "<|vision_end|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151654": { "content": "<|vision_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151655": { "content": "<|image_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151656": { "content": "<|video_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "151657": { "content": "<tool_call>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151658": { "content": "</tool_call>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151659": { "content": "<|fim_prefix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151660": { "content": "<|fim_middle|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151661": { "content": "<|fim_suffix|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151662": { "content": "<|fim_pad|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151663": { "content": "<|repo_name|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151664": { "content": "<|file_sep|>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151665": { "content": "<tool_response>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151666": { "content": "</tool_response>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151667": { "content": "<think>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false }, "151668": { "content": "</think>", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": false } }, "additional_special_tokens": [ "<|im_start|>", "<|im_end|>", "<|object_ref_start|>", "<|object_ref_end|>", "<|box_start|>", "<|box_end|>", "<|quad_start|>", "<|quad_end|>", "<|vision_start|>", "<|vision_end|>", "<|vision_pad|>", "<|image_pad|>", "<|video_pad|>" ], "bos_token": null, "chat_template": "{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0].role == 'system' %}\n {{- messages[0].content + '\\n\\n' }}\n {%- endif %}\n {{- \"# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0].role == 'system' %}\n {{- '<|im_start|>system\\n' + messages[0].content + '<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %}\n{%- for message in messages[::-1] %}\n {%- set index = (messages|length - 1) - loop.index0 %}\n {%- if ns.multi_step_tool and message.role == \"user\" and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %}\n {%- set ns.multi_step_tool = false %}\n {%- set ns.last_query_index = index %}\n {%- endif %}\n{%- endfor %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) %}\n {{- '<|im_start|>' + message.role + '\\n' + message.content + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {%- set content = message.content %}\n {%- set reasoning_content = '' %}\n {%- if message.reasoning_content is defined and message.reasoning_content is not none %}\n {%- set reasoning_content = message.reasoning_content %}\n {%- else %}\n {%- if '</think>' in message.content %}\n {%- set content = message.content.split('</think>')[-1].lstrip('\\n') %}\n {%- set reasoning_content = message.content.split('</think>')[0].rstrip('\\n').split('<think>')[-1].lstrip('\\n') %}\n {%- endif %}\n {%- endif %}\n {%- if loop.index0 > ns.last_query_index %}\n {%- if loop.last or (not loop.last and reasoning_content) %}\n {{- '<|im_start|>' + message.role + '\\n<think>\\n' + reasoning_content.strip('\\n') + '\\n</think>\\n\\n' + content.lstrip('\\n') }}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- else %}\n {{- '<|im_start|>' + message.role + '\\n' + content }}\n {%- endif %}\n {%- if message.tool_calls %}\n {%- for tool_call in message.tool_calls %}\n {%- if (loop.first and content) or (not loop.first) %}\n {{- '\\n' }}\n {%- endif %}\n {%- if tool_call.function %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {%- if tool_call.arguments is string %}\n {{- tool_call.arguments }}\n {%- else %}\n {{- tool_call.arguments | tojson }}\n {%- endif %}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {%- endif %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if loop.first or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- message.content }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n {%- if enable_thinking is defined and enable_thinking is false %}\n {{- '<think>\\n\\n</think>\\n\\n' }}\n {%- endif %}\n{%- endif %}", "clean_up_tokenization_spaces": false, "eos_token": "<|im_end|>", "errors": "replace", "extra_special_tokens": {}, "model_max_length": 131072, "pad_token": "<|endoftext|>", "split_special_tokens": false, "tokenizer_class": "Qwen2Tokenizer", "unk_token": null}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200# /// script# requires-python = ">=3.10"# dependencies = [# "datasets",# "httpx",# "huggingface - hub",# "setuptools",# "transformers",# "torch",# "accelerate",# "trl",# "peft",# "wandb",# "torchvision",# "torchaudio"# ]# ///
"""## Import libraries"""
import torchfrom datasets import load_datasetfrom transformers import AutoModelForCausalLM, AutoTokenizerfrom trl import SFTConfig, SFTTrainer, setup_chat_formatfrom peft import LoraConfig
"""# Load Dataset"""
dataset_name = "allenai/tulu-3-sft-personas-code" # Example dataset
# Load datasetdataset = load_dataset(dataset_name, split="train")print(f"Dataset loaded: {dataset}")
# Let's look at a sampleprint("\nSample data:")print(dataset[0])
dataset = dataset.remove_columns("prompt")dataset = dataset.train_test_split(test_size=0.2)
print( f"Train Samples: {len(dataset['train'])}\nTest Samples: {len(dataset['test'])}")
"""## Configuration
Set up the configuration parameters for the fine-tuning process."""
# Model configurationmodel_name = "Qwen/Qwen3-30B-A3B" # You can change this to any model you want to fine-tune
# # Other compatible Qwen3 models# model_name = "Qwen/Qwen3-32B"# model_name = "Qwen/Qwen3-14B"# model_name = "Qwen/Qwen3-8B"# model_name = "Qwen/Qwen3-4B"# model_name = "Qwen/Qwen3-1.7B"# model_name = "Qwen/Qwen3-0.6B"
# Training configurationoutput_dir = "./tmp/sft-model"num_train_epochs = 1per_device_train_batch_size = 1gradient_accumulation_steps = 1learning_rate = 2e-4
"""## Load model and tokenizer"""
# Load modelmodel = AutoModelForCausalLM.from_pretrained( model_name, torch_dtype=torch.bfloat16, use_cache=False, # Disable KV cache during training device_map="auto",)
# Load tokenizertokenizer = AutoTokenizer.from_pretrained(model_name)
# # Set up chat formatting (if the model doesn't have a chat template)# if tokenizer.chat_template is None:# model, tokenizer = setup_chat_format(model, tokenizer, format="chatml")
# # Set padding token# if tokenizer.pad_token is None:# tokenizer.pad_token = tokenizer.eos_token
"""## Configure PEFT (if enabled)"""
# Set up PEFT configuration if enabledpeft_config = LoraConfig( r=32, # Rank lora_alpha=16, # Alpha parameter for LoRA scaling lora_dropout=0.05, bias="none", task_type="CAUSAL_LM", target_modules="all-linear",)
"""## Configure SFT Trainer"""
# Training argumentstraining_args = SFTConfig( output_dir=output_dir, num_train_epochs=num_train_epochs, per_device_train_batch_size=per_device_train_batch_size, gradient_accumulation_steps=gradient_accumulation_steps, learning_rate=learning_rate, gradient_checkpointing=True, logging_steps=25, save_strategy="epoch", optim="adamw_torch", lr_scheduler_type="cosine", warmup_ratio=0.1, max_length=1024, packing=True, # Enable packing to increase training efficiency eos_token=tokenizer.eos_token, bf16=True, fp16=False, max_steps=1000, report_to="wandb", # Disable reporting to avoid wandb prompts)
"""## Initialize and run the SFT Trainer"""
# Create SFT Trainertrainer = SFTTrainer( model=model, args=training_args, train_dataset=dataset["train"], eval_dataset=dataset["test"] if "test" in dataset else None, peft_config=peft_config, processing_class=tokenizer,)
# Train the modeltrainer.train()
"""## Save the fine-tuned model"""
# Save the modeltrainer.save_model(output_dir)
"""## Test the fine-tuned model"""
from peft import PeftModel, PeftConfig
# Load the base modelbase_model = AutoModelForCausalLM.from_pretrained( model_name, trust_remote_code=True, torch_dtype=torch.bfloat16)
# Load the fine-tuned PEFT modelmodel = PeftModel.from_pretrained(base_model, output_dir)tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)# Test the model with an exampleprompt = """Write a function called is_palindrome that takes a single string as input and returns True if the string is a palindrome, and False otherwise.
Palindrome Definition:
A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, ignoring spaces, punctuation, and capitalization.
Example:```is_palindrome("racecar") # Returns Trueis_palindrome("hello") # Returns Falseis_palindrome("A man, a plan, a canal: Panama") # Returns True```"""
# Format the chat prompt using the tokenizer's chat templatemessages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt},]formatted_prompt = tokenizer.apply_chat_template( messages, tokenize=False, add_generation_prompt=True)print(f"Formatted prompt: {formatted_prompt}")
# Generate responsemodel.eval()inputs = tokenizer(formatted_prompt, return_tensors="pt").to(model.device)with torch.no_grad(): outputs = model.generate( **inputs, max_new_tokens=500, temperature=0.7, top_p=0.9, do_sample=True, pad_token_id=tokenizer.eos_token_id, )response = tokenizer.decode(outputs[0], skip_special_tokens=True)print("\nGenerated Response:")print(response)
model.push_to_hub("burtenshaw/Qwen3-30B-A3B-python-code")123version https://git-lfs.github.com/spec/v1oid sha256:530d75515728e5b50537b8578139e6d2102ba7d965be8b8efe4433401d64e63csize 7377.gitattributesAdded+36
README.mdAdded+59
added_tokens.jsonAdded+28
config.jsonAdded+38
generation_config.jsonAdded+13
merges.txtAdded
model-00001-of-00013.safetensorsAdded+3
model-00002-of-00013.safetensorsAdded+3
model-00003-of-00013.safetensorsAdded+3
model-00004-of-00013.safetensorsAdded+3
model-00005-of-00013.safetensorsAdded+3
model-00006-of-00013.safetensorsAdded+3
model-00007-of-00013.safetensorsAdded+3
model-00008-of-00013.safetensorsAdded+3
model-00009-of-00013.safetensorsAdded+3
model-00010-of-00013.safetensorsAdded+3
model-00011-of-00013.safetensorsAdded+3
model-00012-of-00013.safetensorsAdded+3
model-00013-of-00013.safetensorsAdded+3
model.safetensors.index.jsonAdded
requirements.txtAdded+12
special_tokens_map.jsonAdded+25
tokenizer.jsonAdded+3
tokenizer_config.jsonAdded+240
train.pyAdded+200
training_args.binAdded+3
vocab.jsonAdded