Text Generation
MLX
lora
gemma
code-generation
Prashanth-24's picture
Add Python-code LoRA adapter for gemma-4-e4b-4bit
e596007 verified
|
Raw
History Blame Contribute Delete
2.81 kB
metadata
license: apache-2.0
license_link: https://ai.google.dev/gemma/docs/gemma_4_license
base_model: mlx-community/gemma-4-e4b-4bit
library_name: mlx
pipeline_tag: text-generation
inference: false
tags:
  - mlx
  - lora
  - gemma
  - code-generation
  - text-generation
datasets:
  - iamtarun/python_code_instructions_18k_alpaca

gemma-4-e4b-python-lora

A LoRA adapter that fine-tunes mlx-community/gemma-4-e4b-4bit for Python code generation, trained with mlx_lm.

This repo contains only the adapter weights — you load it on top of the base model, you don't need to download a separate fused model.

Training details

Base model mlx-community/gemma-4-e4b-4bit
Dataset iamtarun/python_code_instructions_18k_alpaca
Fine-tune type LoRA
LoRA rank 8
LoRA scale 20
LoRA dropout 0.0
Layers adapted 16
Learning rate 1e-5
Optimizer Adam
Iterations 500

Training examples were formatted as:

### User:
{instruction}

### Assistant:
{output}

Usage

mlx_lm.load needs the adapter on disk, so download it locally first, then load it exactly as you would a local adapter:

pip install -U mlx-lm huggingface_hub
from huggingface_hub import snapshot_download
from mlx_lm import load, generate

adapter_path = snapshot_download("Prashanth-24/gemma-4-e4b-python-lora")
model, tokenizer = load("mlx-community/gemma-4-e4b-4bit", adapter_path=adapter_path)

prompt = "### User:\nwrite a python code to ADD two numbers\n\n### Assistant:\n"
print(generate(model, tokenizer, prompt=prompt, max_tokens=200))

Example output

Prompt: Create a python program to multiply two numbers.

Base model

Here's a response to your query:

**1. Introduction**

**2. Part I (Body)**

**Introduction**
The concept of unit multiplication is relevant in understanding how to multiply two numbers.

**Part II**

**Part II**

**Key Topics**

**Key Topics**
- **Factors to Consider**
- **Key Topics**
- **Key Topics**
...

Fine-tuned model

def multiply_two_numbers(a, b):
    return a * b

print(multiply_two_numbers(2, 3))

The base model drifts into a generic essay outline and never writes any code. The fine-tuned model answers directly with a correct, runnable Python function — the LoRA clearly taught the ### Assistant: turn to produce code instead of chatter.

Limitations

This is a small run (500 iterations, rank 8). It reliably improves "answer with code" behavior and formatting, but it's a lightweight fine-tune — treat outputs as a draft to review, not production-ready code.