Views
No views yet
1# This is to set the path to save the model
2from pathlib import Path
3
4models_path = Path.home().joinpath('Question_Generation_model', 'UTeMGPT')
5models_path.mkdir(parents=True, exist_ok=True)
6
7# Download the model
8from huggingface_hub import snapshot_download
9my_model = snapshot_download(repo_id="KLimaLima/finetuned-Question-Generation-mistral-7b-instruct", local_dir=models_path)1max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
2dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
3load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
4
5from unsloth import FastLanguageModel
6model, tokenizer = FastLanguageModel.from_pretrained(
7 model_name = my_model,
8 max_seq_length = max_seq_length,
9 dtype = dtype,
10 load_in_4bit = load_in_4bit,
11)
12FastLanguageModel.for_inference(model) # Enable native 2x faster inference1alpaca_prompt = """Below is an instruction that describes a task, paired with an input that provides further context. Write a response that appropriately completes the request.
2
3### Instruction:
4{}
5
6### Input:
7{}
8
9### Response:
10{}"""
11
12instruction = 'Write an inquisitive question about a specific text span in a given sentence such that the answer is not in the text.'
13sentence = "I want to bake a cake during my free time. I need to know the ingredients that need to be use."
14
15inputs = tokenizer(
16[
17 alpaca_prompt.format(
18 instruction,
19 sentence,
20 "", # output - leave this blank for generation!
21 )
22], return_tensors = "pt").to("cuda")
231outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
2tokenizer.batch_decode(outputs)