Skip to content

Commit

Permalink
Peft fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
knc6 committed Oct 4, 2024
1 parent be50121 commit f171615
Showing 1 changed file with 27 additions and 25 deletions.
52 changes: 27 additions & 25 deletions atomgpt/inverse_models/inverse_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from pydantic_settings import BaseSettings
import sys
import argparse
from peft import PeftModelForCausalLM


parser = argparse.ArgumentParser(
description="Atomistic Generative Pre-trained Transformer."
Expand All @@ -38,7 +40,7 @@ class TrainingPropConfig(BaseSettings):
prefix: str = "atomgpt_run"
model_name: str = "unsloth/mistral-7b-bnb-4bit"
batch_size: int = 2
num_epochs: int = 5
num_epochs: int = 2
seed_val: int = 42
num_train: Optional[int] = 2
num_val: Optional[int] = 2
Expand Down Expand Up @@ -164,7 +166,7 @@ def text2atoms(response):
return atoms


def gen_atoms(prompt="", max_new_tokens=512, model="", tokenizer=""):
def gen_atoms(prompt="", max_new_tokens=2048, model="", tokenizer=""):
inputs = tokenizer(
[
alpaca_prompt.format(
Expand All @@ -179,9 +181,7 @@ def gen_atoms(prompt="", max_new_tokens=512, model="", tokenizer=""):
outputs = model.generate(
**inputs, max_new_tokens=max_new_tokens, use_cache=True
)
response = tokenizer.batch_decode(outputs)
print("response", response)
response = response[0].split("# Output:")[1]
response = tokenizer.batch_decode(outputs)[0].split("# Output:")[1]
atoms = None
try:
atoms = text2atoms(response)
Expand Down Expand Up @@ -263,26 +263,28 @@ def run_atomgpt_inverse(config_file="config.json"):
# token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
)

model = FastLanguageModel.get_peft_model(
model,
r=16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128
target_modules=[
"q_proj",
"k_proj",
"v_proj",
"o_proj",
"gate_proj",
"up_proj",
"down_proj",
],
lora_alpha=16,
lora_dropout=0, # Supports any, but = 0 is optimized
bias="none", # Supports any, but = "none" is optimized
use_gradient_checkpointing=True,
random_state=3407,
use_rslora=False, # We support rank stabilized LoRA
loftq_config=None, # And LoftQ
)
if not isinstance(model, PeftModelForCausalLM):

model = FastLanguageModel.get_peft_model(
model,
r=16, # Choose any number > 0 ! Suggested 8, 16, 32, 64, 128
target_modules=[
"q_proj",
"k_proj",
"v_proj",
"o_proj",
"gate_proj",
"up_proj",
"down_proj",
],
lora_alpha=16,
lora_dropout=0, # Supports any, but = 0 is optimized
bias="none", # Supports any, but = "none" is optimized
use_gradient_checkpointing=True,
random_state=3407,
use_rslora=False, # We support rank stabilized LoRA
loftq_config=None, # And LoftQ
)

EOS_TOKEN = tokenizer.eos_token # Must add EOS_TOKEN

Expand Down

0 comments on commit f171615

Please sign in to comment.