sanaa-11 commited on
Commit
ef4100c
·
verified ·
1 Parent(s): 6ddabd3

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +39 -12
README.md CHANGED
@@ -41,23 +41,50 @@ library_name: peft
41
  Use the following code snippet to load and generate exercises using the model:
42
 
43
  ```python
44
- from transformers import AutoModelForCausalLM, AutoTokenizer
 
45
  import torch
46
 
47
- # Load the fine-tuned model
48
- model_name = "sanaa-11/mathematic-exercice-generator"
49
- model = AutoModelForCausalLM.from_pretrained(model_name)
50
- tokenizer = AutoTokenizer.from_pretrained(model_name)
51
 
52
- # Example prompt
53
- prompt = "Crée un exercice de mathématiques sur les équations du premier degré pour les élèves de la 3ème année collège."
 
 
 
 
 
 
54
 
55
- # Generate exercise
56
- inputs = tokenizer(prompt, return_tensors="pt")
57
- outputs = model.generate(**inputs, max_length=150)
58
- generated_exercise = tokenizer.decode(outputs[0], skip_special_tokens=True)
59
 
60
- print(generated_exercise)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  ```
62
  ## Training Details
63
 
 
41
  Use the following code snippet to load and generate exercises using the model:
42
 
43
  ```python
44
+ from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
45
+ from peft import PeftModel, PeftConfig
46
  import torch
47
 
48
+ # Base model name
49
+ model_name = "meta-llama/Meta-Llama-3.1-8B-Instruct"
 
 
50
 
51
+ # Load the base model without specifying rope_scaling
52
+ model = AutoModelForCausalLM.from_pretrained(
53
+ model_name,
54
+ device_map="auto", # Adjust based on your environment
55
+ offload_folder="./offload_dir", # Specify a folder for offloading if necessary
56
+ torch_dtype=torch.float16, # Use float16 for better performance on compatible hardware
57
+ revision="main" # Specify the correct revision if needed
58
+ )
59
 
60
+ # Load the adapter configuration
61
+ config = PeftConfig.from_pretrained("sanaa-11/mathematic-exercice-generator")
 
 
62
 
63
+ # Load the adapter weights into the model
64
+ model = PeftModel.from_pretrained(model, "sanaa-11/mathematic-exercice-generator")
65
+
66
+ # Load the tokenizer
67
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True)
68
+ ```
69
+ ```
70
+ generated_text = ""
71
+ prompt = "Fournis un exercice basé sur la vie reelle de difficulté moyenne de niveau 2 annee college sur les fractions."
72
+ for _ in range(5):
73
+ inputs = tokenizer(prompt + generated_text, return_tensors="pt").to(model.device)
74
+ outputs = model.generate(
75
+ **inputs,
76
+ max_length=1065,
77
+ temperature=0.7,
78
+ top_p=0.9,
79
+ num_beams=5,
80
+ repetition_penalty=1.2,
81
+ no_repeat_ngram_size=2,
82
+ pad_token_id=tokenizer.eos_token_id,
83
+ early_stopping=False
84
+ )
85
+ new_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
86
+ generated_text += new_text
87
+ print(new_text)
88
  ```
89
  ## Training Details
90