Text Generation
Transformers
Safetensors
GGUF
English
code
python
docstring
documentation
code-generation
lora
qlora
smollm2
instruct
causal-lm
conversational
Instructions to use yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0 # Run inference directly in the terminal: llama cli -hf yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0 # Run inference directly in the terminal: llama cli -hf yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0 # Run inference directly in the terminal: ./llama-cli -hf yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0 # Run inference directly in the terminal: ./build/bin/llama-cli -hf yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0
Use Docker
docker model run hf.co/yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0
- LM Studio
- Jan
- vLLM
How to use yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0
- SGLang
How to use yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator 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 "yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator" \ --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": "yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator", "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 "yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator" \ --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": "yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator with Ollama:
ollama run hf.co/yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0
- Unsloth Studio
How to use yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator to start chatting
- Docker Model Runner
How to use yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator with Docker Model Runner:
docker model run hf.co/yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0
- Lemonade
How to use yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator:Q8_0
Run and chat with the model
lemonade run user.SmolLM2-1.7B-Instruct-DocstringGenerator-Q8_0
List all available models
lemonade list
- Atomic Chat
add smol model card
Browse files
README.md
CHANGED
|
@@ -1,10 +1,221 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
license: apache-2.0
|
| 3 |
-
|
| 4 |
-
- bigcode/the-stack-dedup
|
| 5 |
-
- codeparrot/codeparrot-clean
|
| 6 |
-
base_model:
|
| 7 |
-
- HuggingFaceTB/SmolLM2-1.7B-Instruct
|
| 8 |
tags:
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
license: apache-2.0
|
| 5 |
+
library_name: transformers
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
tags:
|
| 7 |
- code
|
| 8 |
+
- python
|
| 9 |
+
- docstring
|
| 10 |
+
- documentation
|
| 11 |
+
- code-generation
|
| 12 |
+
- lora
|
| 13 |
+
- qlora
|
| 14 |
+
- smollm2
|
| 15 |
+
- instruct
|
| 16 |
+
- causal-lm
|
| 17 |
+
base_model: HuggingFaceTB/SmolLM2-1.7B-Instruct
|
| 18 |
+
pipeline_tag: text-generation
|
| 19 |
+
model-index:
|
| 20 |
+
- name: SmolLM2-1.7B-Instruct-DocstringGenerator
|
| 21 |
+
results: []
|
| 22 |
+
datasets:
|
| 23 |
+
- codeparrot/codeparrot-clean
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
+
# SmolLM2-1.7B-Instruct · DocstringGenerator
|
| 27 |
+
|
| 28 |
+
> A fine-tuned **[SmolLM2-1.7B-Instruct](https://huggingface.co/HuggingFaceTB/SmolLM2-1.7B-Instruct)** specialised in writing **concise, high-level Python docstrings** for functions, methods and classes.
|
| 29 |
+
> This model is the backbone of the **[PyDoctor](https://github.com/yezdata/pydoctor)** CLI — a fully local, LLM-powered tool that automatically writes and manages docstrings in your Python codebase.
|
| 30 |
+
|
| 31 |
+
[](https://github.com/yezdata/pydoctor)
|
| 32 |
+
[](LICENSE)
|
| 33 |
+
[](https://www.python.org/)
|
| 34 |
+
[](https://huggingface.co/HuggingFaceTB/SmolLM2-1.7B-Instruct)
|
| 35 |
+
|
| 36 |
+
---
|
| 37 |
+
|
| 38 |
+
## Intended Use
|
| 39 |
+
|
| 40 |
+
The model generates **summary-style docstrings** — single-paragraph, plain-English descriptions of a Python code block's purpose and architectural role. It does **not** produce `Args:`, `Returns:`, or `Raises:` sections by design.
|
| 41 |
+
|
| 42 |
+
**Suitable for:**
|
| 43 |
+
- Automated docstring generation in CI/CD pipelines
|
| 44 |
+
- Interactive IDE plugins
|
| 45 |
+
- Local, privacy-preserving documentation workflows via llama.cpp / GGUF
|
| 46 |
+
|
| 47 |
+
**Not suitable for:**
|
| 48 |
+
- General-purpose code generation
|
| 49 |
+
- Generating full NumPy/Google-style docstrings with parameter tables (explicitly omitted)
|
| 50 |
+
- Non-Python languages
|
| 51 |
+
|
| 52 |
+
---
|
| 53 |
+
|
| 54 |
+
## Quick Start
|
| 55 |
+
### With llama.cpp (GGUF · recommended for local use)
|
| 56 |
+
|
| 57 |
+
```bash
|
| 58 |
+
# Download the Q8_0 GGUF
|
| 59 |
+
huggingface-cli download \
|
| 60 |
+
yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator \
|
| 61 |
+
smollm2_1_7b_instruct_merged-q8_0.gguf \
|
| 62 |
+
--local-dir ./models
|
| 63 |
+
|
| 64 |
+
# Run inference
|
| 65 |
+
llama-cli \
|
| 66 |
+
-m ./models/smollm2_1_7b_instruct_merged-q8_0.gguf \
|
| 67 |
+
--chat-template chatml \
|
| 68 |
+
-p "..."
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
> **Tip:** The [PyDoctor CLI](https://github.com/yezdata/pydoctor) handles prompt construction, parsing, and atomic file rewrites out of the box.
|
| 72 |
+
|
| 73 |
+
---
|
| 74 |
+
|
| 75 |
+
## Prompt Format (ChatML)
|
| 76 |
+
|
| 77 |
+
The model uses the **ChatML** template native to SmolLM2-Instruct:
|
| 78 |
+
|
| 79 |
+
```
|
| 80 |
+
<|im_start|>system
|
| 81 |
+
{SYSTEM_PROMPT}<|im_end|>
|
| 82 |
+
<|im_start|>user
|
| 83 |
+
CONTEXT
|
| 84 |
+
{context_code}
|
| 85 |
+
|
| 86 |
+
TARGET CODE
|
| 87 |
+
{target_code}<|im_end|>
|
| 88 |
+
<|im_start|>assistant
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
The model then generates only the raw docstring text, terminated by `<|im_end|>`.
|
| 92 |
+
|
| 93 |
+
**Context definition:**
|
| 94 |
+
- **function** target -> context = "Independent code block"
|
| 95 |
+
- **method** target → context = `__init__` signature of its enclosing class
|
| 96 |
+
- **class** target → context = signatures of its methods
|
| 97 |
+
|
| 98 |
+
---
|
| 99 |
+
|
| 100 |
+
## Training Pipeline
|
| 101 |
+
|
| 102 |
+
### Stage 1 — Code Extraction
|
| 103 |
+
|
| 104 |
+
Raw Python source files were streamed from **[codeparrot/codeparrot-clean](https://huggingface.co/datasets/codeparrot/codeparrot-clean)** (~200 k samples). Each file passed a quality filter that rejected:
|
| 105 |
+
|
| 106 |
+
| Filter | Threshold |
|
| 107 |
+
|---|---|
|
| 108 |
+
| Too few lines | < 3 non-empty lines |
|
| 109 |
+
| Minified code | avg line length > 150 chars |
|
| 110 |
+
| Low alphabetic ratio | < 15 % (binary / machine-generated) |
|
| 111 |
+
| Repetitive boilerplate | unique line ratio < 10 % |
|
| 112 |
+
| Oversized files | > 50 000 characters |
|
| 113 |
+
|
| 114 |
+
Surviving files were parsed with **[LibCST](https://libcst.readthedocs.io/)** producing `(target, context)` pairs.
|
| 115 |
+
|
| 116 |
+
### Stage 2 — Synthetic Docstring Generation
|
| 117 |
+
|
| 118 |
+
`(target, context)` pairs were labelled in parallel using **DeepSeek V4 Flash** (via OpenRouter):
|
| 119 |
+
|
| 120 |
+
The teacher-model system prompt enforced:
|
| 121 |
+
1. Describe semantic purpose and architectural role, not implementation details
|
| 122 |
+
2. Use context to disambiguate class membership
|
| 123 |
+
|
| 124 |
+
### Stage 3 — Instruct Data Preparation & Tokenisation
|
| 125 |
+
|
| 126 |
+
Synthetic batches were assembled into ChatML prompt/completion pairs:
|
| 127 |
+
|
| 128 |
+
```python
|
| 129 |
+
prompt = (
|
| 130 |
+
f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n"
|
| 131 |
+
f"<|im_start|>user\nCONTEXT\n{context}\n\nTARGET CODE\n{target}<|im_end|>\n"
|
| 132 |
+
f"<|im_start|>assistant\n"
|
| 133 |
+
)
|
| 134 |
+
completion = f"{docstring}<|im_end|>"
|
| 135 |
+
```
|
| 136 |
+
|
| 137 |
+
Labels were constructed so that **only completion tokens** are trained on — prompt tokens are masked from cross-entropy loss.
|
| 138 |
+
|
| 139 |
+
### Stage 4 — QLoRA Fine-tuning
|
| 140 |
+
|
| 141 |
+
Fine-tuning was performed on Kaggle kernels (`instruct_finetune.py`):
|
| 142 |
+
|
| 143 |
+
| Hyperparameter | Value |
|
| 144 |
+
|---|---|
|
| 145 |
+
| Quantisation | 4-bit NF4, double quant, fp16 compute |
|
| 146 |
+
| LoRA rank `r` | 32 |
|
| 147 |
+
| LoRA alpha `α` | 64 |
|
| 148 |
+
| LoRA dropout | 0.2 |
|
| 149 |
+
| LoRA bias | none |
|
| 150 |
+
| Target modules | `q_proj`, `k_proj`, `v_proj`, `o_proj`, `gate_proj`, `up_proj`, `down_proj` |
|
| 151 |
+
| Optimizer | AdamW 8-bit (bitsandbytes) |
|
| 152 |
+
| Learning rate | 2e-4 |
|
| 153 |
+
| LR schedule | Cosine with 5 % warmup |
|
| 154 |
+
| Weight decay | 0.01 |
|
| 155 |
+
| Batch size | 8 per device |
|
| 156 |
+
| Gradient accumulation | 8 steps → effective batch 64 |
|
| 157 |
+
| Epochs | 1 |
|
| 158 |
+
| Max sequence length | 1 024 tokens (95th-pct filter) |
|
| 159 |
+
| Validation split | 1 % held-out, evaluated each epoch |
|
| 160 |
+
| Seed | 1337 |
|
| 161 |
+
|
| 162 |
+
Loss = next-token cross-entropy, **prompt tokens ignored** via label mask.
|
| 163 |
+
|
| 164 |
+
### Stage 5 — LoRA Merge & GGUF Export
|
| 165 |
+
|
| 166 |
+
After training, LoRA adapters were merged back into the base model weights and converted to **Q8_0 GGUF** using `llama.cpp`:
|
| 167 |
+
|
| 168 |
+
```
|
| 169 |
+
LoRA adapter (epoch 1, safetensors)
|
| 170 |
+
│
|
| 171 |
+
▼ merge_and_unload()
|
| 172 |
+
│
|
| 173 |
+
merged fp16 safetensors
|
| 174 |
+
│
|
| 175 |
+
▼ llama.cpp convert_hf_to_gguf.py --outtype q8_0
|
| 176 |
+
▼
|
| 177 |
+
smollm2_1_7b_instruct_merged-q8_0.gguf
|
| 178 |
+
```
|
| 179 |
+
|
| 180 |
+
---
|
| 181 |
+
|
| 182 |
+
## Files
|
| 183 |
+
|
| 184 |
+
| File | Description |
|
| 185 |
+
|---|---|
|
| 186 |
+
| `smollm2_1_7b_instruct_merged-q8_0.gguf` | Q8_0 GGUF for llama.cpp — recommended for local use |
|
| 187 |
+
| `safetensors/model.safetensors` | Merged fp16 weights |
|
| 188 |
+
| `safetensors/config.json` | HuggingFace model configuration |
|
| 189 |
+
| `safetensors/tokenizer.json` / `safetensors/tokenizer_config.json` | SmolLM2-1.7B-Instruct tokenizer |
|
| 190 |
+
|
| 191 |
+
---
|
| 192 |
+
|
| 193 |
+
## Limitations & Bias
|
| 194 |
+
|
| 195 |
+
- **Summary-only style:** the model is trained to output a single-paragraph summary. It will not produce `Args:` / `Returns:` sections.
|
| 196 |
+
- **Python only:** trained exclusively on Python source code from codeparrot-clean.
|
| 197 |
+
- **Context dependency:** quality improves when the correct context string is provided. Passing an empty context for class methods may reduce coherence.
|
| 198 |
+
- **Teacher model bias:** docstring style reflects DeepSeek V4 Flash's preferences filtered through the strict prompt rules. Unusual code idioms may yield generic descriptions.
|
| 199 |
+
- **Not a general assistant:** the model is heavily specialised and will likely perform poorly on tasks other than docstring generation.
|
| 200 |
+
|
| 201 |
+
---
|
| 202 |
+
|
| 203 |
+
## Citation
|
| 204 |
+
|
| 205 |
+
```bibtex
|
| 206 |
+
@misc{pydoctor2026,
|
| 207 |
+
author = {yezdata},
|
| 208 |
+
title = {PyDoctor: Local LLM-powered Python Docstring Generator},
|
| 209 |
+
year = {2026},
|
| 210 |
+
howpublished = {\url{https://github.com/yezdata/pydoctor}},
|
| 211 |
+
note = {Fine-tuned SmolLM2-1.7B-Instruct model available at
|
| 212 |
+
\url{https://huggingface.co/yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator}}
|
| 213 |
+
}
|
| 214 |
+
```
|
| 215 |
+
|
| 216 |
+
---
|
| 217 |
+
|
| 218 |
+
## License
|
| 219 |
+
|
| 220 |
+
This model is released under the **Apache 2.0** license, matching the base `SmolLM2-1.7B-Instruct` model.
|
| 221 |
+
Training data originates from `codeparrot/codeparrot-clean` (MIT)
|