1# Installs Unsloth, Xformers (Flash Attention) and all other packages!2#!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"3#!pip install --no-deps xformers "trl<0.9.0" peft accelerate bitsandbytes45import sentencepiece as spm
6from unsloth import FastLanguageModel
7import torch
8max_seq_length =2048# Choose any! We auto support RoPE Scaling internally!9dtype =None# None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+10load_in_4bit =True# Use 4bit quantization to reduce memory usage. Can be False.11model, tokenizer = FastLanguageModel.from_pretrained(12 model_name="VishnuPJ/MalayaLLM_Gemma_2_9B_Instruct_V1.0",13 max_seq_length=max_seq_length,14 dtype=dtype,15 load_in_4bit=load_in_4bit,16)17EOS_TOKEN = tokenizer.eos_token # Must add EOS_TOKEN18FastLanguageModel.for_inference(model)# Enable native 2x faster inference19#### Giving Instruction with Input20'''
21alpaca_prompt_1 = """ഒരു ചുമതല വിവരിക്കുന്ന ഒരു നിർദ്ദേശം ചുവടെയുണ്ട്.
22 അഭ്യർത്ഥന ശരിയായി പൂർത്തിയാക്കുന്ന ഒരു പ്രതികരണം എഴുതുക.".
23### നിർദ്ദേശം:
24{}
25### ഇൻപുട്ട്:
26{}
27### പ്രതികരണം:
28{}"""
29inputs = tokenizer([
30 alpaca_prompt_1.format(
31 # "Continue the fibonnaci sequence.", # instruction
32 """താഴെ ഉള്ള വാക്യത്തിൽ "അത്" എന്ന് പറയുന്നത് എന്തിനെ ആണ് ?""", # instruction
33""" ഒരു വാഹനം കയറ്റം കയറുക ആയിരുന്നു .അതിൽ 4 ആൾക്കാർ ഉണ്ടായിരുന്നു. """, # input
34 "", # output - leave this blank for generation!
35 )
36], return_tensors = "pt").to("cuda")
37outputs = model.generate(**inputs, max_new_tokens=128, use_cache=True)
38# Printing the result
39print(tokenizer.batch_decode(outputs)[0].split("പ്രതികരണം:\n")[-1])
40'''41## Giving Instruction only.42alpaca_prompt_2 ="""ഒരു ചുമതല വിവരിക്കുന്ന ഒരു നിർദ്ദേശം ചുവടെയുണ്ട്.
43 അഭ്യർത്ഥന ശരിയായി പൂർത്തിയാക്കുന്ന ഒരു പ്രതികരണം എഴുതുക.".
44### നിർദ്ദേശം:
45{}
46### പ്രതികരണം:
47{}"""48whileTrue:49# Taking user input for the instruction50 instruction =input("Enter the instruction (or type 'exit' to quit): ")51if instruction.lower()=='exit':52break53# Preparing the input for the model54 inputs = tokenizer([55 alpaca_prompt_2.format(56 instruction,57"",# output - leave this blank for generation!58)59], return_tensors="pt").to("cuda")60# Generating the output61 outputs = model.generate(**inputs, max_new_tokens=128, use_cache=True)62# Printing the result63print(tokenizer.batch_decode(outputs)[0].split("പ്രതികരണം:\n")[-1])64print("Program terminated.")65
Example Output
Enter instruction (or 'exit' to end): ഒരു സമചതുരത്തിന്റെ ഒരു വശം 4 cm ആണെങ്കിൽ , അതിന്റെ area കണ്ടുപിടിക്കുക..
സമചതുരത്തിന്റെ area 16 cm2 ആണ്.<eos>.
Enter instruction (or 'exit' to end): ഇന്ത്യയുടെ അടുത്ത് സ്ഥിതി ചെയുന്ന നാല് രാജ്യങ്ങളുടെ പേര് പറയുക.
"ഇന്ത്യയ്ക്ക് സമീപമുള്ള നാല് രാജ്യങ്ങൾ ഇവയാണ്:
- നേപ്പാൾ
- ഭൂട്ടാൻ
- ടിബറ്റ് (ചൈന)
- പാകിസ്ഥാൻ"<eos>
Enter instruction (or 'exit' to end):exit
Made Using UNSLOTH
Thanks to Unsloth, the process of fine-tuning large language models (LLMs) has become much easier and more efficient.