Spaces:
Sleeping
Sleeping
Update finetune.py
Browse files- finetune.py +21 -8
finetune.py
CHANGED
|
@@ -31,23 +31,36 @@ if torch.cuda.is_available():
|
|
| 31 |
# 3. Dataset
|
| 32 |
dataset = load_dataset("lamekemal/brvm_finetune")
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
bnb_config = BitsAndBytesConfig(
|
| 35 |
-
load_in_8bit=True,
|
| 36 |
-
|
| 37 |
)
|
| 38 |
|
|
|
|
| 39 |
# 4. Charger modèle + tokenizer (FP16 natif, pas de quantization)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
model = AutoModelForCausalLM.from_pretrained(
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
device_map="auto"
|
| 44 |
-
trust_remote_code=True,
|
| 45 |
-
quantization_config=bnb_config
|
| 46 |
)
|
| 47 |
model.config.use_cache = False
|
| 48 |
model.gradient_checkpointing_enable()
|
| 49 |
|
| 50 |
-
tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
|
|
|
|
|
|
|
| 51 |
if tokenizer.pad_token is None:
|
| 52 |
tokenizer.pad_token = tokenizer.eos_token
|
| 53 |
tokenizer.padding_side = "right"
|
|
|
|
| 31 |
# 3. Dataset
|
| 32 |
dataset = load_dataset("lamekemal/brvm_finetune")
|
| 33 |
|
| 34 |
+
#bnb_config = BitsAndBytesConfig(
|
| 35 |
+
# load_in_8bit=True, # ou load_in_4bit=True pour encore moins de VRAM
|
| 36 |
+
# bnb_8bit_use_fp32_cpu_offload=True, # décharge certains modules sur CPU
|
| 37 |
+
#)
|
| 38 |
+
# Configuration pour 8-bit + offload CPU
|
| 39 |
bnb_config = BitsAndBytesConfig(
|
| 40 |
+
load_in_8bit=True,
|
| 41 |
+
llm_int8_enable_fp32_cpu_offload=True
|
| 42 |
)
|
| 43 |
|
| 44 |
+
|
| 45 |
# 4. Charger modèle + tokenizer (FP16 natif, pas de quantization)
|
| 46 |
+
#model = AutoModelForCausalLM.from_pretrained(
|
| 47 |
+
# base_model,
|
| 48 |
+
# torch_dtype=torch.float16,
|
| 49 |
+
# device_map="auto",
|
| 50 |
+
# trust_remote_code=True,
|
| 51 |
+
# quantization_config=bnb_config
|
| 52 |
+
#)
|
| 53 |
model = AutoModelForCausalLM.from_pretrained(
|
| 54 |
+
"mistralai/Mistral-7B-Instruct-v0.3",
|
| 55 |
+
quantization_config=bnb_config,
|
| 56 |
+
device_map="auto" # ou tu peux préciser {'': 'cpu'} pour offload complet
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
model.config.use_cache = False
|
| 59 |
model.gradient_checkpointing_enable()
|
| 60 |
|
| 61 |
+
#tokenizer = AutoTokenizer.from_pretrained(base_model, trust_remote_code=True)
|
| 62 |
+
tokenizer = AutoTokenizer.from_pretrained("mistralai/Mistral-7B-Instruct-v0.3")
|
| 63 |
+
|
| 64 |
if tokenizer.pad_token is None:
|
| 65 |
tokenizer.pad_token = tokenizer.eos_token
|
| 66 |
tokenizer.padding_side = "right"
|