Views
No views yet
1
2
3import torch
4major_version, minor_version = torch.cuda.get_device_capability()
5
6
7!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
8if major_version >= 8:
9 # Use this for new GPUs like Ampere, Hopper GPUs (RTX 30xx, RTX 40xx, A100, H100, L40)
10 !pip install --no-deps packaging ninja einops flash-attn xformers trl peft accelerate bitsandbytes
11else:
12 # Use this for older GPUs (V100, Tesla T4, RTX 20xx)
13 !pip install --no-deps xformers trl peft accelerate bitsandbytes
14pass
15
16
17
18from unsloth import FastLanguageModel
19import torch
20max_seq_length = 2048
21dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
22load_in_4bit = False
23model, tokenizer = FastLanguageModel.from_pretrained(
24 model_name = "Xhaheen/Shaheen_Gemma_Urdu_",
25 max_seq_length = max_seq_length,
26 dtype = dtype,
27 load_in_4bit = load_in_4bit,
28 device_map="auto"
29)
30FastLanguageModel.for_inference(model) # Enable native 2x faster inference
31
32input_prompt = """
33### Instruction:
34{}
35
36### Input:
37{}
38
39### Response:
40{}"""
41
42input_text = input_prompt.format(
43 "دیئے گئے موضوع کے بارے میں ایک مختصر پیراگراف لکھیں۔", # instruction
44 "قابل تجدید توانائی کے استعمال کی اہمیت", # input
45 "", # output - leave this blank for generation!
46 )
47
48inputs = tokenizer([input_text], return_tensors = "pt").to("cuda")
49
50outputs = model.generate(**inputs, max_new_tokens = 300, use_cache = True)
51
52response = tokenizer.batch_decode(outputs)
531
2from peft import AutoPeftModelForCausalLM
3from transformers import AutoTokenizer
4
5model = AutoPeftModelForCausalLM.from_pretrained(
6 "Xhaheen/Shaheen_Gemma_Urdu_",
7 load_in_4bit = False
8)
9tokenizer = AutoTokenizer.from_pretrained("Xhaheen/Shaheen_Gemma_Urdu_")
10
11
12input_prompt = """
13### Instruction:
14{}
15
16### Input:
17{}
18
19### Response:
20{}"""
21
22
23
24input_text = input_prompt.format(
25 "دیئے گئے موضوع کے بارے میں ایک مختصر پیراگراف لکھیں۔", # instruction
26 "قابل تجدید توانائی کے استعمال کی اہمیت", # input
27 "", # output - leave this blank for generation!
28 )
29
30inputs = tokenizer([input_text], return_tensors = "pt").to("cuda")
31
32outputs = model.generate(**inputs, max_new_tokens = 300, use_cache = True)
33response = tokenizer.batch_decode(outputs)[0]
34