diff --git a/.gitignore b/.gitignore index 127727f..641f087 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ __pycache__ */.ipynb_checkpoints .idea - +.env +venv examples/iris* examples/trainer_* \ No newline at end of file diff --git a/be_great/great.py b/be_great/great.py index 9f9b4e9..690640d 100644 --- a/be_great/great.py +++ b/be_great/great.py @@ -1,3 +1,4 @@ +from typing import List import warnings import json import typing as tp @@ -59,6 +60,7 @@ def __init__( experiment_dir: str = "trainer_great", epochs: int = 100, batch_size: int = 8, + target_modules : List[str] = None, efficient_finetuning: str = "", **train_kwargs, ): @@ -95,13 +97,19 @@ def __init__( "This function requires the 'peft' package. Please install it with - pip install peft==0.9.0" ) + # if not target_modules: + # target_modules = set() + # for name, module in self.model.named_modules(): + # if isinstance(module, (torch.nn.Linear, torch.nn.Embedding, torch.nn.Conv2d)): + # module_name = '.'.join(name.split('.')[4:]).split('.')[0] + # print(module_name) + # target_modules.add(module_name) + # Define LoRA Config lora_config = LoraConfig( r=16, # only training 0.16% of the parameters of the model lora_alpha=32, - target_modules=[ - "c_attn" - ], # this is specific for gpt2 model, to be adapted + target_modules="all-linear" if not target_modules else target_modules, lora_dropout=0.05, bias="none", task_type=TaskType.CAUSAL_LM, # this is specific for gpt2 model, to be adapted @@ -230,7 +238,7 @@ def sample( max_length=max_length, do_sample=True, temperature=temperature, - pad_token_id=50256, + pad_token_id=self.tokenizer.pad_token, ) # Convert tokens back to tabular data diff --git a/requirements.txt b/requirements.txt index 4958fc5..f0237e5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,4 +6,6 @@ torch >= 1.10.2 tqdm >= 4.64.1 transformers >= 4.22.1 accelerate >= 0.20.1 -fsspec >= 2024.5.0 \ No newline at end of file +fsspec >= 2024.5.0 +peft==0.9.0 +bitsandbytes \ No newline at end of file