|
--- |
|
license: apache-2.0 |
|
language: |
|
- sw |
|
- en |
|
--- |
|
|
|
```python |
|
%%capture |
|
# Installs Unsloth, Xformers (Flash Attention) and all other packages! |
|
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git" |
|
!pip install --no-deps "xformers<0.0.27" "trl<0.9.0" peft accelerate bitsandbytes |
|
|
|
|
|
from unsloth import FastLanguageModel |
|
import torch |
|
max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally! |
|
dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+ |
|
load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False. |
|
|
|
model_name = "sartifyllc/sartify_gemma2-2B-16bit" |
|
|
|
|
|
model, tokenizer = FastLanguageModel.from_pretrained( |
|
model_name = model_name, |
|
max_seq_length = max_seq_length, |
|
dtype = dtype, |
|
trust_remote_code=True, |
|
# load_in_4bit = load_in_4bit, |
|
# token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf |
|
) |
|
|
|
alpaca_prompt = """Hapo chini kuna maelezo ya kazi, pamoja na maelezo ya ziada yanayotoa muktadha zaidi. Andika jibu ambalo linakamilisha ombi hilo ipasavyo. |
|
|
|
### Maelezo: |
|
{} |
|
|
|
### Ziada: |
|
{} |
|
|
|
### Jibu: |
|
{}""" |
|
|
|
FastLanguageModel.for_inference(model) # Enable native 2x faster inference |
|
|
|
# alpaca_prompt = Copied from above |
|
|
|
inputs = tokenizer( |
|
[ |
|
alpaca_prompt.format( |
|
"Rudia tu kila kitu ninachosema kwa Kiingereza kwa Kiswahili wala usiseme chochote kingine.", # instruction |
|
"Who is the president of Tanzania?", # input |
|
"", # output - leave this blank for generation! |
|
) |
|
], return_tensors = "pt").to("cuda") |
|
|
|
from transformers import TextStreamer |
|
text_streamer = TextStreamer(tokenizer) |
|
_ = model.generate(**inputs, streamer = text_streamer, max_new_tokens = 128) |
|
|
|
``` |
|
|