File size: 3,643 Bytes
e9f91af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7eb899e
 
 
 
 
e9f91af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
language:
- en
- code
license: apache-2.0
tags:
- code-generation
- code-documentation
- non-autoregressive
- stanford-ncm
- vq-vae
- mcp
- codesearchnet
datasets:
- code_search_net
pipeline_tag: text-generation
---

# NCM Code Documentation (Next-Concept Modeling)

<p align="center">
  <img src="assets/ncm_pipeline.gif" alt="NCM MCP Pipeline" width="780" />
</p>


Fine-tuned checkpoint of Stanford's **Next-Concept Modeling (NCM)** architecture, adapted for ultra-fast, local code documentation and technical function summarization.

- **GitHub Repository**: [artapaher-max/ncm-code-doc](https://github.com/artapaher-max/ncm-code-doc)
- **Base Architecture**: Stanford University / Hazy Research ([HazyResearch/ncm](https://github.com/HazyResearch/ncm))
- **Primary Integration**: Model Context Protocol (MCP) server for local IDE agents (Antigravity IDE, Claude Desktop, Cursor).

---

## Model Architecture & Details

NCM operates in a **non-autoregressive (NAR)** latent space through a 9-level hierarchical Vector-Quantized Variational Autoencoder (VQ-VAE).

- **Non-Autoregressive Generation**: Unlike standard autoregressive LLMs (which decode one token at a time), NCM decodes conceptual representations in parallel across 9 quantization depth levels.
- **Inference Latency**: ~50–100 ms per block on consumer desktop GPUs (e.g., NVIDIA RTX 2060 6GB).
- **Target Context Length**: Bounded to $\le 48$ tokens. Optimized specifically for single-sentence docstrings, function signatures, and concise technical summaries.
- **Prefix Window**: Up to 512 raw tokens of source code.

---

## Intended Use

This model is intended to act as a **lightweight, local writing assistant** offloading routine documentation tasks from large frontier LLMs (Claude 3.5 Sonnet, GPT-4, Gemini):

1. **Token Cost & Latency Reduction**: Avoid spending frontier model tokens on repetitive single-sentence function descriptions.
2. **Local MCP Server**: Run locally alongside coding assistants via stdio MCP.

---

## Quickstart & Usage

### 1. Download Model Checkpoints

Using Python:
```python
from huggingface_hub import snapshot_download

snapshot_download(
    repo_id="r2d2aparicio/ncm-code-doc",
    local_dir="artifacts/ncm_code_doc"
)
```

Files downloaded:
- `generator.pt` (~354 MB): NextConceptTransformer weights.
- `tokenizer.pt` (~299 MB): Hierarchical VQ-VAE tokenizer weights with code-adapted decoder.

### 2. Run with MCP Server

To use this model as a tool in Claude Desktop or Antigravity IDE, clone the official MCP server:

```bash
git clone https://github.com/artapaher-max/ncm-code-doc.git
cd ncm-code-doc
pip install -e .
```

And configure `mcpServers`:
```json
{
  "mcpServers": {
    "ncm-fast-writer": {
      "command": "/path/to/ncm-code-doc/.venv/bin/python",
      "args": ["-u", "/path/to/ncm-code-doc/ncm_doc_server.py"],
      "env": { "PYTHONUNBUFFERED": "1" }
    }
  }
}
```

---

## Training Data & Hardware

- **Dataset**: 5,000 code-docstring pairs sampled from `code_search_net` across Python, JavaScript, and Web repositories.
- **Fine-Tuning Hardware**: Single NVIDIA GeForce RTX 2060 (6 GB VRAM GDDR6).
- **Memory Consumption**: ~2.9 GB VRAM during training (FP16 mixed precision, gradient accumulation, batch size 2).
- **Inference Memory**: ~2.5 GB VRAM.

---

## Citation & Acknowledgments

This model is fine-tuned from the checkpoint provided by Stanford Hazy Research:

```bibtex
@article{ncm2024,
  title={Next-Concept Modeling: Scalable Non-Autoregressive Generation via Hierarchical Latent Space},
  author={Hazy Research, Stanford University},
  journal={arXiv preprint},
  year={2024}
}
```