16
stars
6
commits
Jupyter Notebook
primary language
May 9, 2024
updated
Google Colab Notebook - Llama-3 8b Bangla Inference ScriptOpen the notebook and play with it.
FastLanguageModel from unsloth for 2x faster inference
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "KillerShoaib/llama-3-8b-bangla-lora", ## or KillerShoaib/llama-3-8b-bangla-4bit
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)
Output:
>>> ["<|begin_of_text|>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.\n\n### Instruction:\nসুস্থ থাকার তিনটি উপায় বলুন\n\n### Input:\n\n\n### Response:\n১. নিয়মিত ব্যায়াম করুনঃ নিয়মিত শারীরিক ক্রিয়াকলাপ স্বাস্থ্যকর হওয়ার একটি গুরুত্বপূর্ণ অংশ। এটি শরীরের ওজন হ্রাস করতে, হৃদরোগের স্বাস্থ্য উন্নত করতে এবং শক্তির মাত্রা বাড়াতে সহায়তা করতে পারে। প্রতিদিন কমপক্ষে ৩০ মিনিট মাঝারি তীব্রতার ব্যায়াম করা একটি সুস্থ জীবনযাত্রার জন্য অপরিহার্য। ২. ভারসাম্যপূর্ণ খাদ্য খানঃ একটি সুস্থ জীবনযাত্রার জন্য ভারসাম্যপূর্ণ খাদ্য খাওয়া অত্যন্ত গুরুত্বপূর্ণ। এর অর্থ হ'ল ফল, সবজি, পূর্ণ শস্য, চর্বিযুক্ত প্রোটিন এবং স্বাস্থ্যকর ফ্যাট সহ বিভিন্ন খাদ্য গোষ্ঠী খাওয়া। এটি শরীরকে সঠিকভাবে কাজ করার জন্য প্রয়োজনীয় পুষ্টি সরবরাহ করে এবং স্থূলতা, ডায়াবেটিস এবং হৃদরোগের মতো দীর্ঘস্থায়ী রোগের ঝুঁকি হ্রাস করে। ৩. পর্যাপ্ত ঘুম পানঃ ঘুম শারীরিক ও মানসিক স্বাস্থ্যের জন্য অপরিহার্য। প্রতি রাতে পর্যাপ্ত ঘুম পাওয়া একটি সুস্থ জীবনযাত্রার জন্য অপরিহার্য। এটি শরীরকে পুনরুদ্ধার করতে, প্রতিরোধ ক্ষমতা বাড়াতে এবং মানসিক স্বাস্থ্যের উন্নতি করতে সহায়তা করে। প্রতিদিন পর্যাপ্ত ঘুম পাওয়া এবং একটি স্বাস্থ্যকর ঘুমের প্রোগ্রাম বজায় রাখা গুরুত্বপূর্ণ।<|end_of_text|>"]
AutoModelForPeftCausalLM from Hugginface (only for LoRA adapter model)
from peft import AutoPeftModelForCausalLM
from transformers import AutoTokenizer
model = AutoPeftModelForCausalLM.from_pretrained(
"KillerShoaib/llama-3-8b-bangla-lora",
load_in_4bit = True,
)
tokenizer = AutoTokenizer.from_pretrained("KillerShoaib/llama-3-8b-bangla-lora")
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:
{}"""
inputs = tokenizer(
[
alpaca_prompt.format(
"সুস্থ থাকার তিনটি উপায় বলুন", # instruction
"", # input
"", # output - leave this blank for generation!
)
], return_tensors = "pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens = 1024, use_cache = True)
tokenizer.batch_decode(outputs)
AutoModelForCausalLM from Hugginface (for 4 bit model)from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "KillerShoaib/llama-3-8b-bangla-4bit"
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(
"x পরিবর্তনশীল 4x + 2y = 10 হিসাবে সংজ্ঞায়িত করা হয়। x এর মান খুঁজুন।", # 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)
max_steps instead of num_train_epochs and continue the training from previous checkpoints, instead of training all at once.6 commits
Jupyter Notebook
100.0%
16
stars
6
commits
Jupyter Notebook
primary language
May 9, 2024
updated
Google Colab Notebook - Llama-3 8b Bangla Inference ScriptOpen the notebook and play with it.
FastLanguageModel from unsloth for 2x faster inference
from unsloth import FastLanguageModel
model, tokenizer = FastLanguageModel.from_pretrained(
model_name = "KillerShoaib/llama-3-8b-bangla-lora", ## or KillerShoaib/llama-3-8b-bangla-4bit
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)
Output:
>>> ["<|begin_of_text|>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.\n\n### Instruction:\nসুস্থ থাকার তিনটি উপায় বলুন\n\n### Input:\n\n\n### Response:\n১. নিয়মিত ব্যায়াম করুনঃ নিয়মিত শারীরিক ক্রিয়াকলাপ স্বাস্থ্যকর হওয়ার একটি গুরুত্বপূর্ণ অংশ। এটি শরীরের ওজন হ্রাস করতে, হৃদরোগের স্বাস্থ্য উন্নত করতে এবং শক্তির মাত্রা বাড়াতে সহায়তা করতে পারে। প্রতিদিন কমপক্ষে ৩০ মিনিট মাঝারি তীব্রতার ব্যায়াম করা একটি সুস্থ জীবনযাত্রার জন্য অপরিহার্য। ২. ভারসাম্যপূর্ণ খাদ্য খানঃ একটি সুস্থ জীবনযাত্রার জন্য ভারসাম্যপূর্ণ খাদ্য খাওয়া অত্যন্ত গুরুত্বপূর্ণ। এর অর্থ হ'ল ফল, সবজি, পূর্ণ শস্য, চর্বিযুক্ত প্রোটিন এবং স্বাস্থ্যকর ফ্যাট সহ বিভিন্ন খাদ্য গোষ্ঠী খাওয়া। এটি শরীরকে সঠিকভাবে কাজ করার জন্য প্রয়োজনীয় পুষ্টি সরবরাহ করে এবং স্থূলতা, ডায়াবেটিস এবং হৃদরোগের মতো দীর্ঘস্থায়ী রোগের ঝুঁকি হ্রাস করে। ৩. পর্যাপ্ত ঘুম পানঃ ঘুম শারীরিক ও মানসিক স্বাস্থ্যের জন্য অপরিহার্য। প্রতি রাতে পর্যাপ্ত ঘুম পাওয়া একটি সুস্থ জীবনযাত্রার জন্য অপরিহার্য। এটি শরীরকে পুনরুদ্ধার করতে, প্রতিরোধ ক্ষমতা বাড়াতে এবং মানসিক স্বাস্থ্যের উন্নতি করতে সহায়তা করে। প্রতিদিন পর্যাপ্ত ঘুম পাওয়া এবং একটি স্বাস্থ্যকর ঘুমের প্রোগ্রাম বজায় রাখা গুরুত্বপূর্ণ।<|end_of_text|>"]
AutoModelForPeftCausalLM from Hugginface (only for LoRA adapter model)
from peft import AutoPeftModelForCausalLM
from transformers import AutoTokenizer
model = AutoPeftModelForCausalLM.from_pretrained(
"KillerShoaib/llama-3-8b-bangla-lora",
load_in_4bit = True,
)
tokenizer = AutoTokenizer.from_pretrained("KillerShoaib/llama-3-8b-bangla-lora")
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:
{}"""
inputs = tokenizer(
[
alpaca_prompt.format(
"সুস্থ থাকার তিনটি উপায় বলুন", # instruction
"", # input
"", # output - leave this blank for generation!
)
], return_tensors = "pt").to("cuda")
outputs = model.generate(**inputs, max_new_tokens = 1024, use_cache = True)
tokenizer.batch_decode(outputs)
AutoModelForCausalLM from Hugginface (for 4 bit model)from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "KillerShoaib/llama-3-8b-bangla-4bit"
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(
"x পরিবর্তনশীল 4x + 2y = 10 হিসাবে সংজ্ঞায়িত করা হয়। x এর মান খুঁজুন।", # 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)
max_steps instead of num_train_epochs and continue the training from previous checkpoints, instead of training all at once.6 commits
Jupyter Notebook
100.0%