Instructions to use mshojaei77/gemma-2-2b-fa-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mshojaei77/gemma-2-2b-fa-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mshojaei77/gemma-2-2b-fa-v2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("mshojaei77/gemma-2-2b-fa-v2") model = AutoModelForCausalLM.from_pretrained("mshojaei77/gemma-2-2b-fa-v2") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - llama-cpp-python
How to use mshojaei77/gemma-2-2b-fa-v2 with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="mshojaei77/gemma-2-2b-fa-v2", filename="gemma-2-2b-fa-v2_q8_0.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-2-2b-fa-v2 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-2-2b-fa-v2:Q8_0 # Run inference directly in the terminal: llama-cli -hf mshojaei77/gemma-2-2b-fa-v2: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-2-2b-fa-v2:Q8_0 # Run inference directly in the terminal: llama-cli -hf mshojaei77/gemma-2-2b-fa-v2: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-2-2b-fa-v2:Q8_0 # Run inference directly in the terminal: ./llama-cli -hf mshojaei77/gemma-2-2b-fa-v2: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-2-2b-fa-v2:Q8_0 # Run inference directly in the terminal: ./build/bin/llama-cli -hf mshojaei77/gemma-2-2b-fa-v2:Q8_0
Use Docker
docker model run hf.co/mshojaei77/gemma-2-2b-fa-v2:Q8_0
- LM Studio
- Jan
- vLLM
How to use mshojaei77/gemma-2-2b-fa-v2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mshojaei77/gemma-2-2b-fa-v2" # 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-2-2b-fa-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/mshojaei77/gemma-2-2b-fa-v2:Q8_0
- SGLang
How to use mshojaei77/gemma-2-2b-fa-v2 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-2-2b-fa-v2" \ --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-2-2b-fa-v2", "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-2-2b-fa-v2" \ --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-2-2b-fa-v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use mshojaei77/gemma-2-2b-fa-v2 with Ollama:
ollama run hf.co/mshojaei77/gemma-2-2b-fa-v2:Q8_0
- Unsloth Studio new
How to use mshojaei77/gemma-2-2b-fa-v2 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-2-2b-fa-v2 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-2-2b-fa-v2 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-2-2b-fa-v2 to start chatting
- Docker Model Runner
How to use mshojaei77/gemma-2-2b-fa-v2 with Docker Model Runner:
docker model run hf.co/mshojaei77/gemma-2-2b-fa-v2:Q8_0
- Lemonade
How to use mshojaei77/gemma-2-2b-fa-v2 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull mshojaei77/gemma-2-2b-fa-v2:Q8_0
Run and chat with the model
lemonade run user.gemma-2-2b-fa-v2-Q8_0
List all available models
lemonade list
Persian Gemma 2b (v2)
This repository hosts Persian Gemma 2b v2, an optimized version of the initial Persian Gemma 2b model. This version has undergone further experimental improvements through techniques like self-merging to enhance its performance and efficiency for Persian language conversational tasks.
This model builds upon the foundation of Google's Gemma-2-2b-it and the initial fine-tuning efforts of mshojaei77/Gemma-2b-fa.
Key Improvements in v2
- Optimized Performance: This version incorporates techniques to improve the model's performance in generating Persian text and engaging in conversations.
- Self-Merged: The model has been merged with itself, potentially leading to a more robust and coherent representation.
Important Note: This is still an experimental model and is under active development. While optimizations have been applied, it's crucial to understand that it retains the limitations inherent in a 2 billion parameter model and the early-stage nature of this project. Output quality may vary, and critical evaluation is still necessary.
How to Use
You can use this model just like the original mshojaei77/Gemma-2b-fa, using the transformers library and the pipeline.
import torch
from transformers import pipeline
# Initialize the text generation pipeline
pipe = pipeline(
"text-generation",
model="mshojaei77/gemma-2-2b-fa-v2",
model_kwargs={"torch_dtype": torch.bfloat16},
device="cuda", # Or "mps" for Macs with Apple Silicon
)
# Prepare input messages (using the gemma chat template implicitly)
messages = [
{"role": "user", "content": "سلام چطوری؟"},
]
# Generate a response with a maximum of 512 new tokens
outputs = pipe(messages, max_new_tokens=512, chat_template="gemma") # Explicitly using chat_template for clarity
assistant_response = outputs[0]["generated_text"][-1]["content"].strip()
print(assistant_response)
# Example Output (Illustrative - Output quality may vary significantly):
# سلام! من خوبم، ممنون. شما چطوری؟ 😊
Key Usage Notes:
model="mshojaei77/gemma-2-2b-fa-v2": Make sure to specify the correct model name (v2) in your code.chat_template="gemma": Continue to use thegemmachat template for proper formatting.- Experimental Nature: Expect variable output quality. This is still an experimental model.
Model Details (v2)
- Base Model: google/gemma-2-2b-it
- Previous Version: mshojaei77/Gemma-2b-fa
- Optimization Techniques: Self-Merging, Further Optimization.
- Architecture: Gemma2ForCausalLM (same as base model)
- Model Size: 2 billion parameters
Intended Use
This model is intended for:
- Research and Experimentation: Exploring the impact of Self-Merging techniques on Persian Gemma models.
- Educational Purposes: Demonstrating advanced fine-tuning and optimization methods.
- Community Development: Contributing to the growing ecosystem of Persian language models.
- Prototyping (with caution): For early-stage prototyping, acknowledging its experimental nature.
Limitations
While optimized, this model still has limitations:
- Experimental Stage: Under ongoing development and refinement.
- 2b Parameter Model: Performance is limited by the model size compared to larger models.
- Variable Output Quality: Output quality can still be inconsistent and require careful evaluation.
- Potential for Imperfections: May still exhibit issues like fluency problems, factual inaccuracies, or biases.
Use this model responsibly and be aware of its experimental nature.
Citation:
If you use this model in your research or applications, please cite it using the following DOI: 10.57967/hf/4772
- Downloads last month
- 23
