Views
No views yet
1%%capture
2import os, re
3if "COLAB_" not in "".join(os.environ.keys()):
4 !pip install unsloth
5else:
6 # Do this only in Colab notebooks! Otherwise use pip install unsloth
7 import torch; v = re.match(r"[0-9]{1,}\.[0-9]{1,}", str(torch.__version__)).group(0)
8 xformers = "xformers==" + ("0.0.33.post1" if v=="2.9" else "0.0.32.post2" if v=="2.8" else "0.0.29.post3")
9 !pip install --no-deps bitsandbytes accelerate {xformers} peft trl triton cut_cross_entropy unsloth_zoo
10 !pip install sentencepiece protobuf "datasets==4.3.0" "huggingface_hub>=0.34.0" hf_transfer
11 !pip install --no-deps unsloth
12!pip install transformers==4.56.2
13!pip install --no-deps trl==0.22.21from unsloth import FastLanguageModel
2import torch
3
4model, tokenizer = FastLanguageModel.from_pretrained(
5 model_name = "hmuegyi/Qwen2.5-7B-bnb-en-my-alt",
6 max_seq_length = 2048,
7 load_in_4bit = True, # Memory သက်သာအောင်
8)
9FastLanguageModel.for_inference(model)
10
11alpaca_prompt = """### Instruction:
12You are a professional English-Burmese translator.
13Detect the input language and provide the translation in the opposite language.
14
15### Input:
16{}
17
18### Response:
19{}"""
20
21input_text = "I love Myanmar Country." # you can change input text
22inputs = tokenizer(
23 [
24 alpaca_prompt.format(
25 input_text, # Input
26 "", # Response
27 )
28 ], return_tensors = "pt").to("cuda")
29
30outputs = model.generate(**inputs,
31 max_new_tokens = 128,
32 temperature = 0.1,
33 top_p = 0.5,
34 use_cache = True)
35
36response = tokenizer.batch_decode(outputs)
37
38final_output = response[0].split("### Response:")[1].replace(tokenizer.eos_token, "").strip()
39print(f"Input: {input_text}")
40print(f"Translation: {final_output}")