Views
No views yet
1from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
2from peft import PeftModel, PeftConfig
3import torch
4
5# Base model name
6model_name = "meta-llama/Meta-Llama-3.1-8B-Instruct"
7
8# Load the base model without specifying rope_scaling
9model = AutoModelForCausalLM.from_pretrained(
10 model_name,
11 device_map="auto", # Adjust based on your environment
12 offload_folder="./offload_dir", # Specify a folder for offloading if necessary
13 torch_dtype=torch.float16, # Use float16 for better performance on compatible hardware
14 revision="main" # Specify the correct revision if needed
15)
16
17# Load the adapter configuration
18config = PeftConfig.from_pretrained("sanaa-11/mathematic-exercice-generator")
19
20# Load the adapter weights into the model
21model = PeftModel.from_pretrained(model, "sanaa-11/mathematic-exercice-generator")
22
23# Load the tokenizer
24tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)generated_text = ""
prompt = "Fournis un exercice basé sur la vie reelle de difficulté moyenne de niveau 2 annee college sur les fractions."
for _ in range(5):
inputs = tokenizer(prompt + generated_text, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_length=1065,
temperature=0.7,
top_p=0.9,
num_beams=5,
repetition_penalty=1.2,
no_repeat_ngram_size=2,
pad_token_id=tokenizer.eos_token_id,
early_stopping=False
)
new_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
generated_text += new_text
print(new_text)1@misc{your_name_2024_model,
2 author = {Sanaa Abril},
3 title = {Fine-Tuned LLaMA 3.1 for Generating Math Exercises},
4 year = {2024},
5 publisher = {Hugging Face},
6 note = {\url{https://huggingface.co/sanaa-11/mathematic-exercice-generator}}
7}
8**APA**:
9Abril, S. (2024). Fine-Tuned LLaMA 3.1 for Generating Math Exercises. Hugging Face. https://huggingface.co/sanaa-11/mathematic-exercice-generator
10
11### More Information [optional]
12- For further details or questions, feel free to reach out to the model card authors.
13
14### Model Card Authors [optional]
15- **Sanaa Abril** - sanaa.abril@gmail.com
16
17### Framework versions
18- **Transformers**: 4.44.0
19- **PEFT**: 0.12.0