Instructions to use mshojaei77/gemma-3-4b-persian-v0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mshojaei77/gemma-3-4b-persian-v0 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mshojaei77/gemma-3-4b-persian-v0") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForImageTextToText processor = AutoProcessor.from_pretrained("mshojaei77/gemma-3-4b-persian-v0") model = AutoModelForImageTextToText.from_pretrained("mshojaei77/gemma-3-4b-persian-v0") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - llama-cpp-python
How to use mshojaei77/gemma-3-4b-persian-v0 with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="mshojaei77/gemma-3-4b-persian-v0", filename="gemma-3-4b-persian-v0.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- llama.cpp
How to use mshojaei77/gemma-3-4b-persian-v0 with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf mshojaei77/gemma-3-4b-persian-v0:Q8_0 # Run inference directly in the terminal: llama-cli -hf mshojaei77/gemma-3-4b-persian-v0:Q8_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf mshojaei77/gemma-3-4b-persian-v0:Q8_0 # Run inference directly in the terminal: llama-cli -hf mshojaei77/gemma-3-4b-persian-v0:Q8_0
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf mshojaei77/gemma-3-4b-persian-v0:Q8_0 # Run inference directly in the terminal: ./llama-cli -hf mshojaei77/gemma-3-4b-persian-v0:Q8_0
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf mshojaei77/gemma-3-4b-persian-v0:Q8_0 # Run inference directly in the terminal: ./build/bin/llama-cli -hf mshojaei77/gemma-3-4b-persian-v0:Q8_0
Use Docker
docker model run hf.co/mshojaei77/gemma-3-4b-persian-v0:Q8_0
- LM Studio
- Jan
- vLLM
How to use mshojaei77/gemma-3-4b-persian-v0 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mshojaei77/gemma-3-4b-persian-v0" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mshojaei77/gemma-3-4b-persian-v0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/mshojaei77/gemma-3-4b-persian-v0:Q8_0
- SGLang
How to use mshojaei77/gemma-3-4b-persian-v0 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "mshojaei77/gemma-3-4b-persian-v0" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mshojaei77/gemma-3-4b-persian-v0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "mshojaei77/gemma-3-4b-persian-v0" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mshojaei77/gemma-3-4b-persian-v0", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use mshojaei77/gemma-3-4b-persian-v0 with Ollama:
ollama run hf.co/mshojaei77/gemma-3-4b-persian-v0:Q8_0
- Unsloth Studio new
How to use mshojaei77/gemma-3-4b-persian-v0 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 mshojaei77/gemma-3-4b-persian-v0 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 mshojaei77/gemma-3-4b-persian-v0 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for mshojaei77/gemma-3-4b-persian-v0 to start chatting
- Docker Model Runner
How to use mshojaei77/gemma-3-4b-persian-v0 with Docker Model Runner:
docker model run hf.co/mshojaei77/gemma-3-4b-persian-v0:Q8_0
- Lemonade
How to use mshojaei77/gemma-3-4b-persian-v0 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull mshojaei77/gemma-3-4b-persian-v0:Q8_0
Run and chat with the model
lemonade run user.gemma-3-4b-persian-v0-Q8_0
List all available models
lemonade list
Gemma 3-4B Persian (v0)
mshojaei77/gemma-3-4b-persian-v0 is a Persian-specialized model built on the Gemma 3 architecture. It leverages QLoRA for 4-bit quantization to reduce computational overhead while generating and understanding Persian text. In addition to text generation, the model also retains image input capabilities inherited from its base model.
Usage
This model is compatible with both the Hugging Face Transformers library and Ollama.
Running with Ollama
ollama run mshojaei77/gemma3persian
Running with Hugging Face Transformers
Install Dependencies:
pip install git+https://github.com/huggingface/transformers@v4.49.0-Gemma-3 accelerateLoad Model and Tokenizer:
from transformers import AutoModelForCausalLM, AutoTokenizer import torch model_id = "mshojaei77/gemma-3-4b-persian-v0" model = AutoModelForCausalLM.from_pretrained( model_id, device_map="auto", # Use "cuda" for GPU usage if available torch_dtype=torch.bfloat16, # Alternatively, use torch.float16 ) tokenizer = AutoTokenizer.from_pretrained(model_id) messages = [ { "role": "user", "content": "توماس جفرسون کیست؟" } ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_tensors="pt" ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=200) print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Training Data and Fine-Tuning
Training Dataset
This model was fine-tuned using the mshojaei77/Persian_sft dataset, which contains approximately 681,000 rows of Persian text focused on instruction-following and conversational interactions. The dataset features:
Fine-Tuning
- Method: Supervised Fine-Tuning (SFT) using QLoRA (4-bit quantization)
- Hardware: one T4 GPU
- Software: Utilizes Hugging Face Transformers, with supporting libraries like
peftfor QLoRA andbitsandbytesfor quantization - Trade-offs: Reduced memory footprint at the expense of some precision compared to full-precision models
Evaluation
[SOON]
Usage Considerations and Limitations
Intended Use Cases
- Question Answering: Responding accurately to Persian language queries
- Instruction Following: Interpreting and executing text-based instructions in Persian
- Text Generation: Producing fluent, context-aware Persian content
- Conversational AI: Integrating into chatbots and virtual assistants
- Image Processing: Retaining image input capabilities from the base model
Limitations
- Quantization Impact: 4-bit quantization may reduce output precision and result in occasional incoherent responses.
- Evaluation Scope: Absence of comprehensive evaluation metrics specific to this variant.
- Bias: The model might mirror biases present in both the original Gemma 3 data and the Persian_sft dataset.
- Hallucination: As with all LLMs, there is a risk of generating plausible-sounding but inaccurate information.
- Safety: The model has not undergone safety tuning, so extra caution is advised when deploying in sensitive contexts.
Maintenance and Future Work
This model is under active maintenance. Future updates may include:
- Additional evaluation metrics and benchmarks
- Enhanced safety tuning and bias mitigation strategies
- Expanded documentation and usage examples
- Incorporation of community feedback for iterative improvements
For any queries, contributions, or issues, please contact me.
- Downloads last month
- 724
Model tree for mshojaei77/gemma-3-4b-persian-v0
Base model
google/gemma-3-4b-pt