Instructions to use KillerShoaib/gemma-2-9b-bangla-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use KillerShoaib/gemma-2-9b-bangla-4bit with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="KillerShoaib/gemma-2-9b-bangla-4bit") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("KillerShoaib/gemma-2-9b-bangla-4bit") model = AutoModelForCausalLM.from_pretrained("KillerShoaib/gemma-2-9b-bangla-4bit") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use KillerShoaib/gemma-2-9b-bangla-4bit with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "KillerShoaib/gemma-2-9b-bangla-4bit" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "KillerShoaib/gemma-2-9b-bangla-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/KillerShoaib/gemma-2-9b-bangla-4bit
- SGLang
How to use KillerShoaib/gemma-2-9b-bangla-4bit 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 "KillerShoaib/gemma-2-9b-bangla-4bit" \ --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": "KillerShoaib/gemma-2-9b-bangla-4bit", "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 "KillerShoaib/gemma-2-9b-bangla-4bit" \ --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": "KillerShoaib/gemma-2-9b-bangla-4bit", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio new
How to use KillerShoaib/gemma-2-9b-bangla-4bit 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 KillerShoaib/gemma-2-9b-bangla-4bit 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 KillerShoaib/gemma-2-9b-bangla-4bit to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for KillerShoaib/gemma-2-9b-bangla-4bit to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="KillerShoaib/gemma-2-9b-bangla-4bit", max_seq_length=2048, ) - Docker Model Runner
How to use KillerShoaib/gemma-2-9b-bangla-4bit with Docker Model Runner:
docker model run hf.co/KillerShoaib/gemma-2-9b-bangla-4bit
Gemma-2 Bangla 4 bit
- Developed by: KillerShoaib
- License: apache-2.0
- Finetuned from model : unsloth/gemma-2-9b-it-bnb-4bit
- Datset used for fine-tuning : iamshnoo/alpaca-cleaned-bengali
4-bit Quantization
This is 4-bit quantization of Gemma-2 9b model.
Gemma-2 Bangla Different Formats
LoRA Adapters only- KillerShoaib/gemma-2-9b-bangla-lora16-bit model- KillerShoaib/gemma-2-9b-bangla-16bit
Model Details
Gemma 2 9 billion model was finetuned using unsloth package on a cleaned Bangla alpaca dataset. The model was finetune using LoRA finetuning technique. The model is finetuned for 1 epoch on a single T4 GPU.
Pros & Cons of the Model
Pros
- The model can comprehend the Bangla language, including its semantic nuances
- Given context model can answer the question based on the context
Cons
- Model is unable to do creative or complex work. i.e: creating a poem or solving a math problem in Bangla
- Since the size of the dataset was small, the model lacks lot of general knowledge in Bangla
Llama 3 8b Bangla Vs Gemma 2 9b Bangla
- Overall both performace were similar, the pros and cons both were same, both the model struggle with longer context query and reasoning, but able to answer question if the context is given
Some Examples from the model:
Example 1:
Question: স্সুস্থ থাকার তিনটি উপায় বলুন Model Generated Answer: ১. স্বাস্থ্যকর খাদ্য গ্রহণ করুনঃ ফল, সবজি, পূর্ণ শস্য, চর্বিযুক্ত প্রোটিন এবং স্বাস্থ্যকর ফ্যাট সমৃদ্ধ একটি ভারসাম্যপূর্ণ খাদ্য গ্রহণ করা স্বাস্থ্যকর থাকার একটি গুরুত্বপূর্ণ উপায়। এটি আপনার শরীরকে প্রয়োজনীয় পুষ্টি সরবরাহ করে এবং আপনাকে সুস্থ থাকতে সহায়তা করে। ২. নিয়মিত ব্যায়াম করুনঃ নিয়মিত শারীরিক ক্রিয়াকলাপ আপনার সামগ্রিক স্বাস্থ্যের উন্নতি করতে পারে, আপনার হৃদরোগের স্বাস্থ্য উন্নত করতে পারে, আপনার মানসিক স্বাস্থ্য উন্নত করতে পারে এবং আপনাকে সুস্থ থাকতে সহায়তা করতে পারে। ৩. পর্যাপ্ত ঘুম পানঃ পর্যাপ্ত ঘুম আপনার শরীরকে পুনরুদ্ধার করতে এবং আপনার সামগ্রিক স্বাস্থ্যের উন্নতি করতে সহায়তা করে। প্রতি রাতে ৭-৮ ঘন্টা ঘুম পাওয়া সুস্থ থাকার জন্য গুরুত্বপূর্ণExample 2:
Question: নিচের আলোচনা দেখে বাংলাদেশের রাজধানীর নাম বের করো। Context: বাংলাদেশের রাজধানী ঢাকায় তার নামে একটি এলাকার নামকরন করা হয়েছে শেরেবাংলা নগর (পূর্ববর্তী আইয়ুবনগর ও তারও পূর্বে মনিপুর) ,২০১৪ বাংলাদেশ স্থানীয় সময় শুক্রবার বেলা তিনটায় রাজধানীর ইউনাইটেড হাসপাতালে চিকিৎসাধীন অবস্থায় মারা যান বেবী মওদুদ। মৃত্যুর সময় তার বয়স হয়েছিল ৬৬ বছর।বাংলাদেশ জাতীয় জাদুঘর বাংলাদেশের রাজধানী ঢাকা শহরে অবস্থিত দেশের প্রধান জাদুঘর। এটি ২০, মার্চ, ১৯১৩ খ্রিস্টাব্দে প্রতিষ্ঠিত হয়, এবং ৭ আগস্ট। Model Generated Answer: বাংলাদেশের রাজধানী ঢাকা।Example 3:
Question: বিশ্বের সবচেয়ে বিখ্যাত চিত্রশিল্পী কে? Model Generated Answer: বিশ্বের সবচেয়ে বিখ্যাত চিত্রশিল্পী হিসেবে লেওনার্দো দা ভিঞ্চি সবচেয়ে বেশি পরিচিত। তিনি রেনেসাঁ যুগের একজন বিশিষ্ট চিত্রশিল্পী, উদ্ভাবক, বিজ্ঞানী এবং প্রকৌশলী ছিলেন। তাঁর সবচেয়ে বিখ্যাত কাজগুলির মধ্যে মোনালিসা এবং দ্য লাস্ট সাপার অন্তর্ভুক্ত রয়েছে।
Run The Model
Download the right dependency for Unsloth
Google Colab
%%capture
# Installs Unsloth, Xformers (Flash Attention) and all other packages!
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
# We have to check which Torch version for Xformers (2.3 -> 0.0.27)
from torch import __version__; from packaging.version import Version as V
xformers = "xformers==0.0.27" if V(__version__) < V("2.4.0") else "xformers"
!pip install --no-deps {xformers} trl peft accelerate bitsandbytes triton
FastLanguageModel from unsloth for 2x faster inference
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "KillerShoaib/gemma-2-9b-bangla-4bit", # or KillerShoaib/gemma-2-9b-bangla-4bit / KillerShoaib/gemma-2-9b-bangla-16bit
max_seq_length = 2048,
dtype = None,
load_in_4bit = True,
)
FastLanguageModel.for_inference(model)
# alpaca_prompt for the model
alpaca_prompt = """Below is an instruction in bangla that describes a task, paired with an input also in bangla that provides further context. Write a response in bangla that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
{}"""
# input with instruction and input
inputs = tokenizer(
[
alpaca_prompt.format(
"সুস্থ থাকার তিনটি উপায় বলুন", # instruction
"", # input
"", # output - leave this blank for generation!
)
], return_tensors = "pt").to("cuda")
# generating the output and decoding it
outputs = model.generate(**inputs, max_new_tokens = 2048, use_cache = True)
tokenizer.batch_decode(outputs)
AutoModelForCausalLM from Hugginface
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "KillerShoaib/gemma-2-9b-bangla-4bit" # or KillerShoaib/gemma-2-9b-bangla-16bit
tokenizer_name = model_name
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
# Load model
model = AutoModelForCausalLM.from_pretrained(model_name)
# Text prompt to start generation
alpaca_prompt = """Below is an instruction in bangla that describes a task, paired with an input also in bangla that provides further context. Write a response in bangla that appropriately completes the request.
### Instruction:
{}
### Input:
{}
### Response:
{}"""
# Encode the prompt text
inputs = tokenizer(
[
alpaca_prompt.format(
"বিশ্বের সবচেয়ে বিখ্যাত চিত্রশিল্পী কে?", # instruction
"", # input
"", # output - leave this blank for generation!
)
], return_tensors = "pt").to("cuda")
# output
outputs = model.generate(**inputs, max_new_tokens = 1024, use_cache = True)
tokenizer.batch_decode(outputs)
Inference Script & Github Repo
Google Colab- Gemma-2 9b Bangla Inference ScriptGithub Repo- Llama-3 Bangla
‼️ Github Repo shows how to finetune any unsloth model using incremental training. For Gemma 2 9b model finetuning I've used the exact same logic that was used for Llama 3 8b model. Remember to change the dependency based on the Unsloth notebook example. ‼️
- Downloads last month
- 1
Model tree for KillerShoaib/gemma-2-9b-bangla-4bit
Base model
google/gemma-2-9b