Instructions to use rahul7star/gemma_4_lora with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use rahul7star/gemma_4_lora with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("rahul7star/gemma_4_lora", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Studio
How to use rahul7star/gemma_4_lora with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for rahul7star/gemma_4_lora to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for rahul7star/gemma_4_lora to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for rahul7star/gemma_4_lora to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="rahul7star/gemma_4_lora", max_seq_length=2048, )
| base_model: unsloth/gemma-4-E2B-it | |
| tags: | |
| - text-generation-inference | |
| - transformers | |
| - unsloth | |
| - gemma4 | |
| - trl | |
| license: apache-2.0 | |
| language: | |
| - en | |
| ## Run in kaggle | |
| ``` | |
| # ========================================================= | |
| # Install dependencies (Kaggle usually already has some) | |
| # ========================================================= | |
| !pip install -q transformers peft accelerate bitsandbytes | |
| # ========================================================= | |
| # Imports | |
| # ========================================================= | |
| import torch | |
| from transformers import AutoProcessor, AutoModelForCausalLM | |
| from peft import PeftModel | |
| # ========================================================= | |
| # Config | |
| # ========================================================= | |
| BASE_MODEL = "google/gemma-4-E2B-it" | |
| LORA_MODEL = "rahul7star/gemma_4_lora" | |
| # ========================================================= | |
| # Load processor | |
| # ========================================================= | |
| processor = AutoProcessor.from_pretrained(BASE_MODEL) | |
| # ========================================================= | |
| # Load base model | |
| # ========================================================= | |
| model = AutoModelForCausalLM.from_pretrained( | |
| BASE_MODEL, | |
| torch_dtype=torch.float16, # safer for Kaggle GPU | |
| device_map="auto" | |
| ) | |
| # ========================================================= | |
| # Load LoRA adapter on top of base model | |
| # ========================================================= | |
| model = PeftModel.from_pretrained(model, LORA_MODEL) | |
| # optional: merge LoRA for faster inference | |
| model = model.merge_and_unload() | |
| print("Model + LoRA loaded successfully 🚀") | |
| # ========================================================= | |
| # Inference function | |
| # ========================================================= | |
| def generate_response(user_input): | |
| messages = [ | |
| {"role": "system", "content": "You are a helpful assistant."}, | |
| {"role": "user", "content": user_input}, | |
| ] | |
| text = processor.apply_chat_template( | |
| messages, | |
| tokenize=False, | |
| add_generation_prompt=True, | |
| enable_thinking=False | |
| ) | |
| inputs = processor(text=text, return_tensors="pt").to(model.device) | |
| input_len = inputs["input_ids"].shape[-1] | |
| with torch.no_grad(): | |
| outputs = model.generate( | |
| **inputs, | |
| max_new_tokens=512, | |
| temperature=0.7, | |
| top_p=0.9 | |
| ) | |
| response = processor.decode( | |
| outputs[0][input_len:], | |
| skip_special_tokens=True | |
| ) | |
| return response | |
| # ========================================================= | |
| # Test | |
| # ========================================================= | |
| print(generate_response("Write a short joke about saving RAM.")) | |
| ``` | |
| # Uploaded model | |
| - **Developed by:** rahul7star | |
| - **License:** apache-2.0 | |
| - **Finetuned from model :** unsloth/gemma-4-E2B-it | |
| This gemma4 model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) | |
| [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth) | |