GhostScientist's picture
Clarify adapter usage and beginner-friendly model card
5b3f201 verified
|
Raw History Blame Contribute Delete
5.3 kB
---
base_model: Qwen/Qwen2.5-Coder-7B-Instruct
library_name: transformers
model_name: deepwiki-coder-7b-v2
tags:
- generated_from_trainer
- sft
- trl
- hf_jobs
- ml-intern
- deepwiki
- code-documentation
- technical-writing
license: apache-2.0
---
# DeepWiki Coder 7B v2
## What?
This is a LoRA adapter fine-tuned from [Qwen2.5-Coder-7B-Instruct](https://huggingface.co/Qwen/Qwen2.5-Coder-7B-Instruct) to generate **DeepWiki-style codebase wiki pages** — structured technical documentation with source file references, Mermaid diagrams, Markdown tables, and inline citations.
Because this repository contains adapter weights rather than a standalone base model, it must be loaded with the Qwen base model and PEFT. A merged standalone version is available at [GhostScientist/semanticwiki-coder-7b-v2-merged](https://huggingface.co/GhostScientist/semanticwiki-coder-7b-v2-merged).
## Why?
The adapter format is small and convenient for experimentation or further fine-tuning. Merging it with the base model makes deployment simpler and is the required preparation step for conversion to Apple-Silicon MLX format.
## What It Does
Given source code files and a topic, this model generates a complete technical wiki page with:
- **`<details>` source file block** at the top listing all relevant files
- **H1/H2/H3 markdown sections** with introduction, detailed analysis, and conclusion
- **Mermaid diagrams** (flowchart TD, sequenceDiagram) showing architecture and data flow
- **Markdown tables** summarizing key information
- **Source citations** in `Sources: [path:line]()` format referencing specific files
## Training Details
| Parameter | Value |
|---|---|
| Base model | Qwen/Qwen2.5-Coder-7B-Instruct |
| Method | LoRA SFT (Supervised Fine-Tuning) |
| LoRA rank | 64 |
| LoRA alpha | 128 |
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
| Epochs | 4 |
| Learning rate | 2e-4 |
| Effective batch size | 16 |
| Max sequence length | 12288 |
| Training examples | 28 |
| Training data | [GhostScientist/deepwiki-sft-v2](https://huggingface.co/datasets/GhostScientist/deepwiki-sft-v2) |
| Hardware | NVIDIA A100-SXM4-80GB |
| Final loss | 0.2488 |
| Token accuracy | 92.4% |
### v2 Improvements over v1
| Metric | v1 Training Data | v2 Training Data |
|---|---|---|
| Proper citation format | 19% | 100% |
| Mermaid diagrams | 52% | 100% |
| Markdown tables | 0% | 100% |
| Avg citations/example | 0.4 | 6.8 |
The v2 training data was generated with few-shot prompting and post-processing to enforce DeepWiki format requirements (citations, diagrams, tables) that were missing or inconsistent in v1.
## Usage
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
import torch
base_model_id = "Qwen/Qwen2.5-Coder-7B-Instruct"
adapter_model_id = "GhostScientist/semanticwiki-coder-7b-v2"
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
model = AutoModelForCausalLM.from_pretrained(base_model_id, dtype=torch.bfloat16, device_map="auto")
model = PeftModel.from_pretrained(model, adapter_model_id)
model = model.merge_and_unload()
messages = [
{"role": "system", "content": "You are an expert code analyst..."},
{"role": "user", "content": "<START_OF_CONTEXT>\n[source code here]\n<END_OF_CONTEXT>\n\n<query>\nGenerate a wiki page about...\n</query>"},
]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=4096, temperature=0.7, top_p=0.9, do_sample=True)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))
```
## Training Infrastructure
- **Training job**: [HF Jobs](https://huggingface.co/jobs/GhostScientist/6aa322ee5527934177ec2d8f)
- **Trackio dashboard**: [GhostScientist/ml-intern-d8f3a2b1](https://huggingface.co/spaces/GhostScientist/ml-intern-d8f3a2b1)
- **Training script**: TRL SFTTrainer with LoRA via PEFT
- **Monitoring**: Trackio with alert callbacks for divergence/NaN/overfitting detection
## Framework Versions
- TRL: 1.13.0
- Transformers: 5.17.0
- PyTorch: 2.14.0
- PEFT: 0.20.0
- Datasets: 5.0.1
- Tokenizers: 0.23.2
## Related Resources
- [v1 Model](https://huggingface.co/GhostScientist/deepwiki-coder-7b) (previous iteration)
- [v2 Training Dataset](https://huggingface.co/datasets/GhostScientist/deepwiki-sft-v2)
- [v1 Eval Results](https://huggingface.co/datasets/GhostScientist/deepwiki-eval-results)
## Citations
```bibtex
@software{vonwerra2020trl,
title = {{TRL: Transformers Reinforcement Learning}},
author = {vonwerra, Leandro and Belkada, Younes and Tunstall, Lewis and Beeching, Edward and Thrush, Tristan and Lambert, Nathan and Huang, Shengyi and Rasul, Kashif and Gallouédec, Quentin},
license = {Apache-2.0},
url = {https://github.com/huggingface/trl},
year = {2020}
}
```
<!-- ml-intern-provenance -->
## Generated by ML Intern
This model repository was generated by [ML Intern](https://github.com/huggingface/ml-intern), an agent for machine learning research and development on the Hugging Face Hub.
- Try ML Intern: https://smolagents-ml-intern.hf.space
- Source code: https://github.com/huggingface/ml-intern