Instructions to use Prashanth-24/gemma-4-e4b-python-lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use Prashanth-24/gemma-4-e4b-python-lora with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # if on a CUDA device, also pip install mlx[cuda] # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("Prashanth-24/gemma-4-e4b-python-lora") prompt = "Once upon a time in" text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- MLX LM
How to use Prashanth-24/gemma-4-e4b-python-lora with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Generate some text mlx_lm.generate --model "Prashanth-24/gemma-4-e4b-python-lora" --prompt "Once upon a time"
Add Python-code LoRA adapter for gemma-4-e4b-4bit
Browse files- README.md +109 -0
- adapter_config.json +41 -0
- adapters.safetensors +3 -0
README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
license_link: https://ai.google.dev/gemma/docs/gemma_4_license
|
| 4 |
+
base_model: mlx-community/gemma-4-e4b-4bit
|
| 5 |
+
library_name: mlx
|
| 6 |
+
pipeline_tag: text-generation
|
| 7 |
+
inference: false
|
| 8 |
+
tags:
|
| 9 |
+
- mlx
|
| 10 |
+
- lora
|
| 11 |
+
- gemma
|
| 12 |
+
- code-generation
|
| 13 |
+
- text-generation
|
| 14 |
+
datasets:
|
| 15 |
+
- iamtarun/python_code_instructions_18k_alpaca
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# gemma-4-e4b-python-lora
|
| 19 |
+
|
| 20 |
+
A LoRA adapter that fine-tunes [`mlx-community/gemma-4-e4b-4bit`](https://huggingface.co/mlx-community/gemma-4-e4b-4bit)
|
| 21 |
+
for Python code generation, trained with [`mlx_lm`](https://github.com/ml-explore/mlx-lm).
|
| 22 |
+
|
| 23 |
+
This repo contains **only the adapter weights** — you load it on top of the base
|
| 24 |
+
model, you don't need to download a separate fused model.
|
| 25 |
+
|
| 26 |
+
## Training details
|
| 27 |
+
|
| 28 |
+
| | |
|
| 29 |
+
|---|---|
|
| 30 |
+
| Base model | `mlx-community/gemma-4-e4b-4bit` |
|
| 31 |
+
| Dataset | [`iamtarun/python_code_instructions_18k_alpaca`](https://huggingface.co/datasets/iamtarun/python_code_instructions_18k_alpaca) |
|
| 32 |
+
| Fine-tune type | LoRA |
|
| 33 |
+
| LoRA rank | 8 |
|
| 34 |
+
| LoRA scale | 20 |
|
| 35 |
+
| LoRA dropout | 0.0 |
|
| 36 |
+
| Layers adapted | 16 |
|
| 37 |
+
| Learning rate | 1e-5 |
|
| 38 |
+
| Optimizer | Adam |
|
| 39 |
+
| Iterations | 500 |
|
| 40 |
+
|
| 41 |
+
Training examples were formatted as:
|
| 42 |
+
|
| 43 |
+
```
|
| 44 |
+
### User:
|
| 45 |
+
{instruction}
|
| 46 |
+
|
| 47 |
+
### Assistant:
|
| 48 |
+
{output}
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
## Usage
|
| 52 |
+
|
| 53 |
+
`mlx_lm.load` needs the adapter on disk, so download it locally first, then load it
|
| 54 |
+
exactly as you would a local adapter:
|
| 55 |
+
|
| 56 |
+
```bash
|
| 57 |
+
pip install -U mlx-lm huggingface_hub
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
```python
|
| 61 |
+
from huggingface_hub import snapshot_download
|
| 62 |
+
from mlx_lm import load, generate
|
| 63 |
+
|
| 64 |
+
adapter_path = snapshot_download("Prashanth-24/gemma-4-e4b-python-lora")
|
| 65 |
+
model, tokenizer = load("mlx-community/gemma-4-e4b-4bit", adapter_path=adapter_path)
|
| 66 |
+
|
| 67 |
+
prompt = "### User:\nwrite a python code to ADD two numbers\n\n### Assistant:\n"
|
| 68 |
+
print(generate(model, tokenizer, prompt=prompt, max_tokens=200))
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
## Example output
|
| 72 |
+
|
| 73 |
+
Prompt: `write a python code to ADD two numbers`
|
| 74 |
+
|
| 75 |
+
**Base model**
|
| 76 |
+
|
| 77 |
+
```
|
| 78 |
+
Here is your code:
|
| 79 |
+
|
| 80 |
+
### response:
|
| 81 |
+
The code to add two numbers is:
|
| 82 |
+
|
| 83 |
+
### Response:
|
| 84 |
+
Here is your response:
|
| 85 |
+
The response to your query is:
|
| 86 |
+
...
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
**Fine-tuned model**
|
| 90 |
+
|
| 91 |
+
```python
|
| 92 |
+
def add_numbers(a, b):
|
| 93 |
+
if b == 0:
|
| 94 |
+
return a
|
| 95 |
+
else:
|
| 96 |
+
return a / b
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
The base model loops into repetitive, non-answering text. The fine-tuned model
|
| 100 |
+
reliably switches into clean, structured Python — the LoRA clearly taught the
|
| 101 |
+
`### Assistant:` turn to produce code instead of chatter.
|
| 102 |
+
|
| 103 |
+
## Limitations
|
| 104 |
+
|
| 105 |
+
This is a small run (500 iterations, rank 8). Formatting and "answer with code"
|
| 106 |
+
behavior improved a lot, but generalization is imperfect — in the example above the
|
| 107 |
+
fine-tuned model actually emits a *division* function with a zero-check, not a sum,
|
| 108 |
+
for an "add two numbers" prompt. Treat outputs as a draft to review, not
|
| 109 |
+
production-ready code.
|
adapter_config.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"adapter_path": "./adapters_python",
|
| 3 |
+
"batch_size": 1,
|
| 4 |
+
"clear_cache_threshold": 0,
|
| 5 |
+
"config": null,
|
| 6 |
+
"data": "./data_python_alpaca",
|
| 7 |
+
"fine_tune_type": "lora",
|
| 8 |
+
"grad_accumulation_steps": 1,
|
| 9 |
+
"grad_checkpoint": false,
|
| 10 |
+
"iters": 500,
|
| 11 |
+
"learning_rate": 1e-05,
|
| 12 |
+
"lora_parameters": {
|
| 13 |
+
"rank": 8,
|
| 14 |
+
"dropout": 0.0,
|
| 15 |
+
"scale": 20.0
|
| 16 |
+
},
|
| 17 |
+
"lr_schedule": null,
|
| 18 |
+
"mask_prompt": false,
|
| 19 |
+
"max_seq_length": 1024,
|
| 20 |
+
"model": "mlx-community/gemma-4-e4b-4bit",
|
| 21 |
+
"num_layers": 16,
|
| 22 |
+
"optimizer": "adam",
|
| 23 |
+
"optimizer_config": {
|
| 24 |
+
"adam": {},
|
| 25 |
+
"adamw": {},
|
| 26 |
+
"muon": {},
|
| 27 |
+
"sgd": {},
|
| 28 |
+
"adafactor": {}
|
| 29 |
+
},
|
| 30 |
+
"project_name": null,
|
| 31 |
+
"report_to": null,
|
| 32 |
+
"resume_adapter_file": null,
|
| 33 |
+
"save_every": 100,
|
| 34 |
+
"seed": 0,
|
| 35 |
+
"steps_per_eval": 50,
|
| 36 |
+
"steps_per_report": 10,
|
| 37 |
+
"test": false,
|
| 38 |
+
"test_batches": 500,
|
| 39 |
+
"train": true,
|
| 40 |
+
"val_batches": 25
|
| 41 |
+
}
|
adapters.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9579543548bf8a5110569233b1a08ed8a597cfbd06b7ce33a690a7ae45096166
|
| 3 |
+
size 30935924
|