--- license: bigcode-openrail-m language: - en library_name: transformers pipeline_tag: text-generation base_model: Kuantum-ai1/TinyCode1.2-164M-Python tags: - code - python - instruct --- # TinyCode1.2-164M-Python-Instruct A small Python instruction-tuned model: [`Kuantum-ai1/TinyCode1.2-164M-Python`](https://huggingface.co/Kuantum-ai1/TinyCode1.2-164M-Python) fine-tuned on 30M tokens (2 epochs) of Python instruction pairs plus plain Python code. It answers a request with one fenced Python code block. ## Prompt format ``` ### Instruction: {your request} ### Response: ```python ``` The model writes the code and a closing code fence, then stops (EOS). `tokenizer.apply_chat_template` produces this format. Pre-filling the opening code fence (see Usage) works best. ## Training - Base model: `Kuantum-ai1/TinyCode1.2-164M-Python` - Data (30M tokens): 21.4M tokens of instruction pairs (response = the Python code block of the answer; loss only on the response) from [`iamtarun/python_code_instructions_18k_alpaca`](https://huggingface.co/datasets/iamtarun/python_code_instructions_18k_alpaca), [`nickrosh/Evol-Instruct-Code-80k-v1`](https://huggingface.co/datasets/nickrosh/Evol-Instruct-Code-80k-v1), [`bigcode/self-oss-instruct-sc2-exec-filter-50k`](https://huggingface.co/datasets/bigcode/self-oss-instruct-sc2-exec-filter-50k) and [`ise-uiuc/Magicoder-OSS-Instruct-75K`](https://huggingface.co/datasets/ise-uiuc/Magicoder-OSS-Instruct-75K), plus 8.6M tokens of plain Python from [`jon-tow/starcoderdata-python-edu`](https://huggingface.co/datasets/jon-tow/starcoderdata-python-edu) to keep completion ability. Several of these datasets are LLM-generated; check their licenses before commercial use. - Filtering: valid Python (`ast.parse`), length and line-length limits, alphabetic-ratio check, exact deduplication, and removal of any sample that shares a normalized line (40+ chars, imports excluded) with HumanEval, any MBPP split or BigCodeBench, or contains an MBPP task description (1217 candidate samples removed). The packed data was re-scanned after tokenization as a final check. - Hardware: 2x NVIDIA T4 (DDP, fp16 mixed precision), sequence length 1024, batch 32k tokens, peak LR 2e-05, cosine schedule ## Evaluation Greedy decoding for pass@1 (%), identical harness for every row (max 200 new tokens). MBPP (500 test problems) is zero-shot with the task and the first test in the prompt; the "instruct template" row wraps the same prompt in the training format. MBPP pass@3 uses the unbiased estimator of Chen et al. (2021) from 5 sampled completions per problem (temperature 0.8, top_p 0.95). This is a lightweight harness (asserts run in a subprocess, 10 s timeout, only the libraries preinstalled on Kaggle, prompts longer than the 1024-token context count as failed). | Model | Params | MBPP pass@1 | MBPP pass@3 | |---|---|---|---| | Kuantum-ai1/TinyCode1.2-164M-Python-Instruct (raw prompt) | 164M | 14.0 | 19.84 | | Kuantum-ai1/TinyCode1.2-164M-Python-Instruct (instruct template) | 164M | 13.0 | 18.7 | | Kuantum-ai1/TinyCode1.2-164M-Python (previous) | 164M | 8.8 | 13.56 | | Base: bigcode/tiny_starcoder_py | 164M | 4.8 | - | Instruct (template) vs the previous version: MBPP pass@1 +4.20, pass@3 +5.14 (absolute points). The base row's MBPP pass@1 comes from an earlier run of the same harness; pass@3 was not measured for it. ## MBPP+ [MBPP+](https://huggingface.co/datasets/evalplus/mbppplus) (378 problems, EvalPlus extended tests), same prompts and decoding as the MBPP table above: pass@1 is greedy, pass@3 is the unbiased estimator from 5 samples (temperature 0.8, top_p 0.95), max 200 new tokens. A problem counts only if the code passes all extended tests (20 s timeout). This is a lightweight harness, not the official EvalPlus pipeline, so the numbers are not directly comparable with the EvalPlus leaderboard. The reference solutions pass 99.7% of the problems in this harness. | Model | Params | MBPP+ pass@1 | MBPP+ pass@3 | |---|---|---|---| | Kuantum-ai1/TinyCode1.2-164M-Python-Instruct (raw prompt) | 164M | 19.31 | 21.67 | | Kuantum-ai1/TinyCode1.2-164M-Python-Instruct (instruct template) | 164M | 16.93 | 23.12 | | Kuantum-ai1/TinyCode1.2-164M-Python (previous) | 164M | 11.9 | 16.06 | | Base: bigcode/tiny_starcoder_py | 164M | 7.94 | 8.68 | Instruct (template) vs the previous version: MBPP+ pass@1 +5.03, pass@3 +7.06 (absolute points). ## GGUF - `TinyCode1.2-164M-Python-Instruct-Q4_0.gguf` (126 MB) - `TinyCode1.2-164M-Python-Instruct-Q4_K_M.gguf` (134 MB) - `TinyCode1.2-164M-Python-Instruct-Q4_K_S.gguf` (127 MB) - `TinyCode1.2-164M-Python-Instruct-Q5_K_M.gguf` (145 MB) - `TinyCode1.2-164M-Python-Instruct-Q6_K.gguf` (157 MB) - `TinyCode1.2-164M-Python-Instruct-Q8_0.gguf` (195 MB) ## Usage ```python from transformers import AutoModelForCausalLM, AutoTokenizer tok = AutoTokenizer.from_pretrained("Kuantum-ai1/TinyCode1.2-164M-Python-Instruct") model = AutoModelForCausalLM.from_pretrained("Kuantum-ai1/TinyCode1.2-164M-Python-Instruct") msgs = [{"role": "user", "content": "Write a function that returns the n-th Fibonacci number."}] prompt = tok.apply_chat_template(msgs, tokenize=False) + "```python\n" ids = tok(prompt, return_tensors="pt") out = model.generate(**ids, max_new_tokens=200, do_sample=False) print(tok.decode(out[0][ids["input_ids"].shape[1]:], skip_special_tokens=True).split("\n```")[0]) ``` ## Limitations Small model: it makes frequent mistakes and should not be relied on for production code. It only answers with Python code (no explanations) and has a 1024-token context. Generated code must be reviewed before use. ## License bigcode-openrail-m