DanH-Walpole commited on
Commit
20bf36f
·
1 Parent(s): edcff0a

Update README with comprehensive model card

Browse files
Files changed (1) hide show
  1. README.md +143 -34
README.md CHANGED
@@ -1,44 +1,153 @@
1
- ---
2
- base_model: google/gemma-3-270m-it
3
- license: gemma
4
- tags:
5
- - gemma3
6
- - gemma
7
- - google
8
- - mlx
9
- pipeline_tag: text-generation
10
- library_name: mlx
11
- extra_gated_heading: Access Gemma on Hugging Face
12
- extra_gated_prompt: To access Gemma on Hugging Face, you’re required to review and
13
- agree to Google’s usage license. To do this, please ensure you’re logged in to Hugging
14
- Face and click below. Requests are processed immediately.
15
- extra_gated_button_content: Acknowledge license
16
- ---
17
-
18
- # hks350d/git-diff-to-commit-gemma-3-270m
19
-
20
- This model [hks350d/git-diff-to-commit-gemma-3-270m](https://huggingface.co/hks350d/git-diff-to-commit-gemma-3-270m) was
21
- converted to MLX format from [google/gemma-3-270m-it](https://huggingface.co/google/gemma-3-270m-it)
22
- using mlx-lm version **0.26.3**.
23
-
24
- ## Use with mlx
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  ```bash
27
- pip install mlx-lm
 
 
28
  ```
29
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  ```python
31
- from mlx_lm import load, generate
 
 
 
 
 
 
32
 
33
- model, tokenizer = load("hks350d/git-diff-to-commit-gemma-3-270m")
 
 
 
 
 
 
 
34
 
35
- prompt = "hello"
 
36
 
37
- if tokenizer.chat_template is not None:
38
- messages = [{"role": "user", "content": prompt}]
39
- prompt = tokenizer.apply_chat_template(
40
- messages, add_generation_prompt=True
41
- )
42
 
43
- response = generate(model, tokenizer, prompt=prompt, verbose=True)
 
 
44
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Git Diff -> Commit Message (Gemma 3 270M IT + LoRA)
2
+
3
+ A small, fast model specialized to turn a git diff into a concise, English commit message. Built on top of `google/gemma-3-270m-it` and fine-tuned with LoRA using MLX on macOS.
4
+
5
+ ## What this model expects (most important)
6
+
7
+ - Input type: a unified git diff as plain text.
8
+ - Wrap the diff in a Markdown code fence labeled `diff` for best results:
9
+ ```
10
+ ```diff
11
+ <your unified git diff here>
12
+ ```
13
+ ```
14
+ - The diff should look like the output of `git diff --no-color` (hunk headers like `@@`, `+`/`-` line prefixes, file headers, etc.).
15
+ - Keep diffs reasonably sized. The training/CLI path truncates diffs to ~3,000 characters and trains/infers with a context window of ~2,048 tokens. Extremely large diffs should be summarized or sampled.
16
+ - Language of response: English only. The system prompt enforces English output.
17
+
18
+ ### Chat template (Gemma 3)
19
+ The model was trained and inferred using Gemma’s chat template. Conceptually:
20
+
21
+ - system: "You are a helpful assistant that generates git commit messages. Always respond in English only. Do not use any other language."
22
+ - user: "Generate a concise and descriptive commit message for this git diff:" + the diff wrapped in ```diff fences
23
+ - assistant: single-line commit message (target)
24
+
25
+ Training data (chat format) examples were stored like:
26
+
27
+ ```json
28
+ {
29
+ "messages": [
30
+ {"role": "system", "content": "You are a helpful assistant that generates git commit messages. Always respond in English only. Do not use any other language."},
31
+ {"role": "user", "content": "Generate a concise and descriptive commit message for this git diff:\n\n```diff\n<diff text>\n```"},
32
+ {"role": "assistant", "content": "<single-line commit message>"}
33
+ ]
34
+ }
35
+ ```
36
+
37
+ ## Output
38
+
39
+ - A single-line commit subject, in English.
40
+ - The CLI post-processes the generation and returns the first non-empty line.
41
+ - Keep it concise and descriptive; optionally target ~50–72 characters where possible.
42
+
43
+ ## Quick usage
44
+
45
+ ### CLI (included in this repo)
46
+ - From a staged diff in your current repo:
47
 
48
  ```bash
49
+ python commit_msg_cli.py run --from-git --staged --adapter \
50
+ --model google/gemma-3-270m-it \
51
+ --adapter-path ./adapters
52
  ```
53
 
54
+ - From a diff file:
55
+
56
+ ```bash
57
+ python commit_msg_cli.py run --diff path/to/diff.txt --adapter \
58
+ --model google/gemma-3-270m-it \
59
+ --adapter-path ./adapters
60
+ ```
61
+
62
+ The CLI will wrap your diff with the expected prompt/template and return a single-line message.
63
+
64
+ ### Programmatic (MLX)
65
+
66
  ```python
67
+ from mlx_lm.utils import load as mlx_load
68
+ from mlx_lm.generate import generate
69
+ from chat_template_utils import get_gemma_tokenizer, format_commit_message_prompt
70
+ from mlx_lm import sample_utils
71
+
72
+ model_name = "google/gemma-3-270m-it"
73
+ adapter_path = "./adapters" # or a specific run dir
74
 
75
+ diff_text = """diff --git a/app.py b/app.py
76
+ index e69de29..f4c3b4a 100644
77
+ --- a/app.py
78
+ +++ b/app.py
79
+ @@ -0,0 +1,3 @@
80
+ +def add(a, b):
81
+ + return a + b
82
+ +"""
83
 
84
+ # Load with adapter if available
85
+ model, tok = mlx_load(model_name, adapter_path=adapter_path)
86
 
87
+ # Use Gemma chat template for the prompt
88
+ tokenizer = get_gemma_tokenizer(model_name)
89
+ prompt = format_commit_message_prompt(diff_text, tokenizer, include_generation_prompt=True)
 
 
90
 
91
+ sampler = sample_utils.make_sampler(temp=0.7, top_p=0.9, top_k=64)
92
+ out = generate(model, tok, prompt=prompt, max_tokens=100, verbose=False, sampler=sampler)
93
+ print(out)
94
  ```
95
+
96
+ ## Examples
97
+
98
+ Input (user message content):
99
+
100
+ ```diff
101
+ diff --git a/app.py b/app.py
102
+ index e69de29..f4c3b4a 100644
103
+ --- a/app.py
104
+ +++ b/app.py
105
+ @@ -0,0 +1,3 @@
106
+ +def add(a, b):
107
+ + return a + b
108
+ +
109
+ ```
110
+
111
+ Possible outputs:
112
+ - Add simple add() helper
113
+ - Implement add function
114
+ - Introduce add utility for two-number sum
115
+
116
+ ## Training summary
117
+
118
+ - Base model: `google/gemma-3-270m-it` (Gemma 3, 270M, instruction-tuned).
119
+ - Method: LoRA fine-tuning with MLX (`mlx_lm lora`). Prompt masking was enabled so the model learns from the assistant response.
120
+ - Data: Local JSONL converted to chat format with diffs fenced as ```diff and English, single-line commit messages as targets. In this repo, the dataset used (`data/train_gpt-oss-20b.jsonl`) was parsed and converted to a chat messages format. This particular set is Python-focused.
121
+ - Context/config highlights: max sequence length ~2048 tokens; diffs truncated to ~3,000 characters during preprocessing/inference to be model-friendly.
122
+
123
+ ## Evaluation
124
+
125
+ - The repo includes a lightweight evaluation that compares generated messages to a reference using a simple string similarity (SequenceMatcher) across multiple runs (varying the RNG seed). Results and artifacts are saved under `evaluation_results/`.
126
+
127
+ ## Limitations and risks
128
+
129
+ - Diff size sensitivity: Very large diffs may be truncated; consider summarizing large changes.
130
+ - Domain bias: Training set emphasized Python diffs; behavior may be better for Python-heavy repos.
131
+ - Hallucinations: As with any LLM, may produce generic or mismatched messages if the diff is ambiguous.
132
+ - Security: Do not feed secrets; generated text may inadvertently paraphrase sensitive context.
133
+ - Language: System prompt enforces English responses.
134
+
135
+ ## Intended use
136
+
137
+ - Assist developers by proposing a concise commit subject from a given git diff.
138
+ - Not a replacement for human judgment; review messages before committing.
139
+
140
+ ## How to format inputs yourself
141
+
142
+ If you’re not using the CLI helpers, follow this structure with the Gemma chat template:
143
+
144
+ - system: English-only instruction for commit message generation (see above)
145
+ - user: instruction + the diff in ```diff code fences
146
+ - assistant: the target single-line subject (for training) or left empty (for inference)
147
+
148
+ The repository’s `format_commit_message_prompt` builds the correct prompt for Gemma 3.
149
+
150
+ ## License and credits
151
+
152
+ - Base model: Google Gemma 3 (`google/gemma-3-270m-it`). Use subject to the Gemma license terms.
153
+ - Fine-tuning code: MLX and utilities in this repository. See repository license for details.