File size: 5,093 Bytes
0d37291
c8c2578
 
 
 
 
 
 
 
 
 
 
 
 
0d37291
c8c2578
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
license: other
license_name: openmdw-1.1
license_link: https://huggingface.co/harshit2312/dory-4b-toolsmith-lora/blob/main/LICENSE.OpenMDW-1.1.txt
base_model: nvidia/NVIDIA-Nemotron-Labs-Dory1.0-4B-BF16
library_name: peft
pipeline_tag: text-generation
tags:
- lora
- peft
- code-repair
- tool-use
- sft
- grpo
---

# Toolsmith LoRA adapters for Dory 1.0 4B

Two LoRA adapters for [NVIDIA Nemotron Labs Dory 1.0 4B](https://huggingface.co/nvidia/NVIDIA-Nemotron-Labs-Dory1.0-4B-BF16)
that repair small single-function Python bugs through four tools (`read_file`,
`edit_file`, `run_visible_tests`, `submit_patch`) in the Toolsmith episode protocol.
Code, task generator, sandbox, recorded runs, and the comparison and viewer tools:
https://github.com/hr231/toolsmith-rl

| Subfolder | Method | Best at |
| --- | --- | --- |
| `sft/` | LoRA SFT on 500 verified demonstrations | Overall accuracy (97.4%) |
| `grpo/` | Stateful GRPO from the prompt-only model, no demonstrations | Hardest split (challenge 34/40) |

## Evaluation

| Model | dev | test_iid | test_compositional | challenge | All |
| --- | --- | --- | --- | --- | --- |
| Prompt-only Dory 1.0 4B | 82/100 | 80/100 | 70/100 | 23/40 | 255/340 (75.0%) |
| SFT LoRA | 100/100 | 100/100 | 100/100 | 31/40 | 331/340 (97.4%) |
| GRPO LoRA (from prompt-only) | 98/100 | 92/100 | 95/100 | 34/40 | 319/340 (93.8%) |

Same 340 frozen tasks for every model (seed 17, temperature 1.0, top_p 0.95, 256 new
tokens per turn, 8 tool calls per episode). A task counts only if the submitted
patch passes private input/output checks in a fresh Docker container. No model
submitted a wrong patch.

- **`sft`:** +22.4 points over the prompt-only model (95% CI +17.9 to +26.8; 77 tasks
  gained, 1 lost), mostly from concise tool use: 150 new tokens per episode instead
  of 308.
- **`grpo`:** +18.8 points over the prompt-only model (95% CI +14.1 to +23.5; 70 tasks
  gained, 6 lost) and the best model on the challenge split. Overall it trails `sft`
  by 3.5 points (95% CI -5.9 to -1.2); 18 of its 21 failures are turns that ran past
  the 256-token limit.

## Training

- **`sft`:** one epoch over 500 replay-verified demonstrations (read file, run tests,
  edit, run tests, submit): 63 optimizer steps, learning rate 2e-4 with 3 warmup
  steps then linear decay, 8-example accumulation, gradient clipping at 1.0. Loss
  covers only the tokens the model generates at inference (tool calls and the
  end-of-turn token).
- **`grpo`:** TRL GRPO from a fresh LoRA on the prompt-only model: 150 steps, one
  train task per step, 4 independent multi-turn episodes per task, learning rate
  2e-5, KL 0.02 against the frozen starting adapter, dropout disabled. Reward is 1
  when the submitted patch passes the private checks, else 0; tool results are
  masked from the loss. Only 14 of the 150 steps had reward variance. One T4, 4.9
  hours.
- **Shared:** rank 16, alpha 32, dropout 0.05 on the 180 linear layers inside the
  base model's attention blocks (15.6M parameters); the MLPs and the LM head are not
  adapted. fp16 base weights with fp32 LoRA weights on T4 GPUs.
- GRPO started from `sft` received no reward variance in 150 steps and ended
  identical to `sft`, so it is not included.

## Usage

The base model needs Transformers from huggingface/transformers#50099 (commit
`fcc6924dfbac964f00787859b568c867ef5ad4cb`) until Dory support is released.

```python
import torch
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer

base = "nvidia/NVIDIA-Nemotron-Labs-Dory1.0-4B-BF16"
revision = "f6c832e6963ddb74f62c75813a3e8c74b1af67b1"
tokenizer = AutoTokenizer.from_pretrained(base, revision=revision)
model = AutoModelForCausalLM.from_pretrained(base, revision=revision, dtype=torch.float16)
model = PeftModel.from_pretrained(model, "harshit2312/dory-4b-toolsmith-lora", subfolder="sft").merge_and_unload()
```

Use `subfolder="grpo"` for the GRPO adapter. Prompts, tool schemas, and the strict
tool-call parser are in `toolsmith.inference`; `toolsmith.evaluation.run_episode`
runs a full episode against a sandbox. Settings used for every result: 2 recurrent
loops, `enable_thinking=False`, temperature 1.0, top_p 0.95. Run generated code only
inside an isolated sandbox.

## Limitations

- Trained and evaluated on synthetic, templated, single-function tasks; results do
  not transfer to real repositories.
- Single training seed; confidence intervals cover task sampling only.
- `sft` learned the demonstrations' fixed five-call script: after a failed test it
  re-submits unchanged code or re-runs the test until its budget ends.
- `grpo` still over-explains on some edit turns (18 of 340 tasks end truncated), and
  recovery after a second failing test remains rare.
- The base model's terms apply, including NVIDIA's guidance in its model card.

## License and notice

Distributed under the [OpenMDW-1.1](LICENSE.OpenMDW-1.1.txt) agreement with this
notice of origin: "NVIDIA-Nemotron-Labs-Dory1.0-4B-BF16, by NVIDIA, under
OpenMDW-1.1." Using the adapters requires the base model under its own terms.