Aller au contenu
ModelPrésentéExterne
Télécharger

SmolLM2 1.7B Instruct DocstringGenerator

> A fine-tuned SmolLM2-1.7B-Instruct specialised in writing concise, high-level Python docstrings for functions, methods and classes. > This model is the backbone of the PyDoctor CLI — a fully local, LLM-powered tool...

TypeOtherModèle de baseHuggingFaceTB/SmolLM2-1.7B-InstructVersionRevision 28bdf3dBClasse

Source du modèle

Type
Other
Taille du fichier
1,70–3,19 GB
Modèle de base
HuggingFaceTB/SmolLM2-1.7B-Instruct
Version
vRevision 28bdf3d
Mis à jour
20 oct. 2026
Téléchargements
24
Source
Hugging Face

Description de la source

SmolLM2-1.7B-Instruct · DocstringGenerator

A fine-tuned SmolLM2-1.7B-Instruct specialised in writing concise, high-level Python docstrings for functions, methods and classes. This model is the backbone of the PyDoctor CLI — a fully local, LLM-powered tool that automatically writes and manages docstrings in your Python codebase.

GitHub License Python Base Model


Intended Use

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.

Suitable for:

  • Automated docstring generation in CI/CD pipelines
  • Interactive IDE plugins
  • Local, privacy-preserving documentation workflows via llama.cpp / GGUF

Not suitable for:

  • General-purpose code generation
  • Generating full NumPy/Google-style docstrings with parameter tables (explicitly omitted)
  • Non-Python languages

Quick Start

With llama.cpp (GGUF · recommended for local use)

# Download the Q8_0 GGUF
huggingface-cli download \
  yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator \
  smollm2_1_7b_instruct_merged-q8_0.gguf \
  --local-dir ./models

# Run inference
llama-cli \
  -m ./models/smollm2_1_7b_instruct_merged-q8_0.gguf \
  --chat-template chatml \
  -p "..."

Tip: The PyDoctor CLI handles prompt construction, parsing, and atomic file rewrites out of the box.


Prompt Format (ChatML)

The model uses the ChatML template native to SmolLM2-Instruct:

<|im_start|>system
{SYSTEM_PROMPT}<|im_end|>
<|im_start|>user
CONTEXT
{context_code}

TARGET CODE
{target_code}<|im_end|>
<|im_start|>assistant

The model then generates only the raw docstring text, terminated by <|im_end|>.

Context definition:

  • function target -> context = "Independent code block"
  • method target → context = __init__ signature of its enclosing class
  • class target → context = signatures of its methods

Training Pipeline

Stage 1 — Code Extraction

Raw Python source files were streamed from codeparrot/codeparrot-clean (~200 k samples). Each file passed a quality filter that rejected:

FilterThreshold
Too few lines< 3 non-empty lines
Minified codeavg line length > 150 chars
Low alphabetic ratio< 15 % (binary / machine-generated)
Repetitive boilerplateunique line ratio < 10 %
Oversized files> 50 000 characters

Surviving files were parsed with LibCST producing (target, context) pairs.

Stage 2 — Synthetic Docstring Generation

(target, context) pairs were labelled in parallel using DeepSeek V4 Flash (via OpenRouter):

The teacher-model system prompt enforced:

  1. Describe semantic purpose and architectural role, not implementation details
  2. Use context to disambiguate class membership

Stage 3 — Instruct Data Preparation & Tokenisation

Synthetic batches were assembled into ChatML prompt/completion pairs:

prompt = (
    f"<|im_start|>system\n{SYSTEM_PROMPT}<|im_end|>\n"
    f"<|im_start|>user\nCONTEXT\n{context}\n\nTARGET CODE\n{target}<|im_end|>\n"
    f"<|im_start|>assistant\n"
)
completion = f"{docstring}<|im_end|>"

Labels were constructed so that only completion tokens are trained on — prompt tokens are masked from cross-entropy loss.

Stage 4 — QLoRA Fine-tuning

Fine-tuning was performed on Kaggle kernels (instruct_finetune.py):

HyperparameterValue
Quantisation4-bit NF4, double quant, fp16 compute
LoRA rank r32
LoRA alpha α64
LoRA dropout0.2
LoRA biasnone
Target modulesq_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
OptimizerAdamW 8-bit (bitsandbytes)
Learning rate2e-4
LR scheduleCosine with 5 % warmup
Weight decay0.01
Batch size8 per device
Gradient accumulation8 steps → effective batch 64
Epochs1
Max sequence length1 024 tokens (95th-pct filter)
Validation split1 % held-out, evaluated each epoch
Seed1337

Loss = next-token cross-entropy, prompt tokens ignored via label mask.

Stage 5 — LoRA Merge & GGUF Export

After training, LoRA adapters were merged back into the base model weights and converted to Q8_0 GGUF using llama.cpp:

LoRA adapter (epoch 1, safetensors)
        │
        ▼  merge_and_unload()
        │
merged fp16 safetensors
        │
        ▼  llama.cpp convert_hf_to_gguf.py --outtype q8_0
        ▼
smollm2_1_7b_instruct_merged-q8_0.gguf

Files

FileDescription
smollm2_1_7b_instruct_merged-q8_0.ggufQ8_0 GGUF for llama.cpp — recommended for local use
safetensors/model.safetensorsMerged fp16 weights
safetensors/config.jsonHuggingFace model configuration
safetensors/tokenizer.json / safetensors/tokenizer_config.jsonSmolLM2-1.7B-Instruct tokenizer

Limitations & Bias

  • Summary-only style: the model is trained to output a single-paragraph summary. It will not produce Args: / Returns: sections.
  • Python only: trained exclusively on Python source code from codeparrot-clean.
  • Context dependency: quality improves when the correct context string is provided. Passing an empty context for class methods may reduce coherence.
  • Teacher model bias: docstring style reflects DeepSeek V4 Flash's preferences filtered through the strict prompt rules. Unusual code idioms may yield generic descriptions.
  • Not a general assistant: the model is heavily specialised and will likely perform poorly on tasks other than docstring generation.

Citation

@misc{pydoctor2026,
  author       = {yezdata},
  title        = {PyDoctor: Local LLM-powered Python Docstring Generator},
  year         = {2026},
  howpublished = {\url{https://github.com/yezdata/pydoctor}},
  note         = {Fine-tuned SmolLM2-1.7B-Instruct model available at
                  \url{https://huggingface.co/yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator}}
}

License

This model is released under the Apache 2.0 license, matching the base SmolLM2-1.7B-Instruct model.
Training data originates from codeparrot/codeparrot-clean (MIT)

Sources

1 source
Hugging FacePrincipalVersion 28bdf3d1667ce561b06c95944103fb4615c15573
huggingface.co/yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator/tree/28bdf3d1667ce561b06c95944103fb4615c15573

Vérifié 20 oct.

Artefacts du modèle

2 artefacts

safetensors/model.safetensors

safetensors · 3,19 GB · SHA-256 aa3f38dd222a…e25e · Hugging Face

Télécharger

smollm2_1_7b_instruct_merged-q8_0.gguf

gguf · 1,70 GB · SHA-256 bf2ef7dbd77a…d0f2 · Hugging Face

Télécharger

Extraits de sources

3 extraits

--- language: - en license: apache-2.0 library_name: transformers tags: - code - python - docstring - documentation - code-generation - lora - qlora - smollm2 - instruct - causal-lm base_model: HuggingFaceTB/SmolLM2-1.7B-Instruct pipeline_tag: text-generation model-index: - name: SmolLM2-1.7B-Instruct-DocstringGenerator results: [] datasets: - codeparrot/codeparrot-clean --- # SmolLM2-1.7B-Instruct · DocstringGenerator > 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. > 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. [![GitHub](https://img.shields.io/badge/GitHub-yezdata%2Fpydoctor-black?logo=github)](https://github.com/yezdata/pydoctor) [![License](https://img.shields.io/badge/license-Apache%202.0-blue)](LICENSE) [![Python](https://img.shields.io/badge/python-3.12-blue?logo=python)](https://www.python.org/) [![Base Model](https://img.shields.io/badge/base-SmolLM2--1.7B--Instruct-yellow?logo=huggingface)](https://huggingface.co/HuggingFaceTB/SmolLM2-1.7B-Instruct) --- ## Intended Use 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. **Suitable for:** - Automated docstring generation in CI/CD pipelines - Interactive IDE plugins - Local, privacy-preserving documentation workflows via llama.cpp / GGUF **Not suitable for:** - General-purpose code generation - Generating full NumPy/Google-style docstrings with parameter tables (explicitly omitted) - Non-Python languages --- ## Quick Start ### With llama.cpp (GGUF · recommended for local use) ```bash # Download the Q8_0 GGUF huggingface-cli download \ yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator \ smollm2_1_7b_instruct_merged-q8_0.gguf \ --local-dir ./models # Run inference llama-cli \ -m ./models/smollm2_1_7b_instruct_merged-q8_0.gguf \ --chat-template chatml \ -p "..." ``` > **Tip:** The [PyDoctor CLI](https://github.com/yezdata/pydoctor) handles prompt construction, parsing, and atomic file rewrites out of th...

Source context: 24 downloads · 1 likes · Pipeline text-generation · Library transformers · Repo yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator

Source context: 112 downloads · 1 likes · Pipeline text-generation · Library transformers · Repo yezdata/SmolLM2-1.7B-Instruct-DocstringGenerator