Jiacheng-Zhu-AIML / AsymmetryLoRA

Preprint: Asymmetry in Low-Rank Adapters of Foundation Models
29 stars 1 forks source link

Cannot run the demo or script for `run_glue_origin_ft.py` #3

Closed Free-Dreamer closed 1 month ago

Free-Dreamer commented 1 month ago

Sorry but I think this repo may be not ready to be published yet. I cannot even run the demo in the usage or run_glue_origin_ft.py for the GLUE benchmark. When I run the demo in the usage, it raises an error:

XXXX object has no attribute '_is_prompt_learning'

where XXX is a class of sequence classification model based on either GPT2 or roberta.

When I run the scripts for the GLUE benchmark, it raises a similar error:

AttributeError: 'RobertaForSequenceClassification' object has no attribute '_is_prompt_learning'

I follow the instruction to install the environment and try different versions of peft and transformers. I think it is the bug of the code itself. Could you help to address those issues? @Jiacheng-Zhu-AIML

For lib info:

_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
accelerate                0.33.0                   pypi_0    pypi
aiohappyeyeballs          2.3.7                    pypi_0    pypi
aiohttp                   3.10.4                   pypi_0    pypi
aiosignal                 1.3.1                    pypi_0    pypi
appdirs                   1.4.4              pyh9f0ad1d_0    conda-forge
asttokens                 2.4.1              pyhd8ed1ab_0    conda-forge
async-timeout             4.0.3                    pypi_0    pypi
attrs                     24.2.0                   pypi_0    pypi
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
beautifulsoup4            4.12.3             pyha770c72_0    conda-forge
blas                      1.0                         mkl  
brotli                    1.1.0                hd590300_1    conda-forge
brotli-bin                1.1.0                hd590300_1    conda-forge
brotli-python             1.0.9            py38h6a678d5_8  
bzip2                     1.0.8                h4bc722e_7    conda-forge
ca-certificates           2024.7.4             hbcca054_0    conda-forge
certifi                   2024.7.4           pyhd8ed1ab_0    conda-forge
charset-normalizer        3.3.2              pyhd3eb1b0_0  
click                     8.1.7           unix_pyh707e725_0    conda-forge
contourpy                 1.1.1            py38h7f3f72f_1    conda-forge
cycler                    0.12.1             pyhd8ed1ab_0    conda-forge
datasets                  2.21.0                   pypi_0    pypi
dbus                      1.13.18              hb2f20db_0  
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
docker-pycreds            0.4.0                      py_0    conda-forge
evaluate                  0.4.2                    pypi_0    pypi
executing                 2.0.1              pyhd8ed1ab_0    conda-forge
expat                     2.6.2                h59595ed_0    conda-forge
filelock                  3.15.4             pyhd8ed1ab_0    conda-forge
fontconfig                2.14.2               h14ed4e7_0    conda-forge
fonttools                 4.53.1           py38h2019614_0    conda-forge
freetype                  2.12.1               h4a9f257_0  
frozenlist                1.4.1                    pypi_0    pypi
fsspec                    2024.6.1                 pypi_0    pypi
gdown                     5.2.0              pyhd8ed1ab_0    conda-forge
gitdb                     4.0.11             pyhd8ed1ab_0    conda-forge
gitpython                 3.1.43             pyhd8ed1ab_0    conda-forge
glib                      2.80.2               hf974151_0    conda-forge
glib-tools                2.80.2               hb6ce0ca_0    conda-forge
gst-plugins-base          1.14.1               h6a678d5_1  
gstreamer                 1.14.1               h5eee18b_1  
huggingface-hub           0.24.5                   pypi_0    pypi
icu                       58.2              hf484d3e_1000    conda-forge
idna                      3.7              py38h06a4308_0  
importlib-resources       6.4.2              pyhd8ed1ab_0    conda-forge
importlib_resources       6.4.2              pyhd8ed1ab_0    conda-forge
intel-openmp              2023.1.0         hdb19cb5_46306  
ipdb                      0.13.13            pyhd8ed1ab_0    conda-forge
ipython                   8.12.2             pyh41d4057_0    conda-forge
jbig                      2.1               h7f98852_2003    conda-forge
jedi                      0.19.1             pyhd8ed1ab_0    conda-forge
joblib                    1.4.2            py38h06a4308_0  
jpeg                      9e                   h0b41bf4_3    conda-forge
keyutils                  1.6.1                h166bdaf_0    conda-forge
kiwisolver                1.4.5            py38h7f3f72f_1    conda-forge
krb5                      1.20.1               h81ceb04_0    conda-forge
lcms2                     2.12                 hddcbb42_0    conda-forge
ld_impl_linux-64          2.38                 h1181459_1  
lerc                      2.2.1                h9c3ff4c_0    conda-forge
libbrotlicommon           1.1.0                hd590300_1    conda-forge
libbrotlidec              1.1.0                hd590300_1    conda-forge
libbrotlienc              1.1.0                hd590300_1    conda-forge
libclang                  10.0.1          default_hde54327_1    conda-forge
libdeflate                1.7                  h7f98852_5    conda-forge
libedit                   3.1.20191231         he28a2e2_2    conda-forge
libevent                  2.1.12               hf998b51_1    conda-forge
libexpat                  2.6.2                h59595ed_0    conda-forge
libffi                    3.4.4                h6a678d5_1  
libgcc-ng                 14.1.0               h77fa898_0    conda-forge
libgfortran-ng            11.2.0               h00389a5_1  
libgfortran5              11.2.0               h1234567_1  
libglib                   2.80.2               hf974151_0    conda-forge
libgomp                   14.1.0               h77fa898_0    conda-forge
libiconv                  1.17                 hd590300_2    conda-forge
libllvm10                 10.0.1               he513fc3_3    conda-forge
libpng                    1.6.37               h21135ba_2    conda-forge
libpq                     12.17                hdbd6064_0  
libprotobuf               3.20.1               h4ff587b_0  
libsqlite                 3.46.0               hde9e2c9_0    conda-forge
libstdcxx-ng              14.1.0               hc0a3c3a_0    conda-forge
libtiff                   4.3.0                hf544144_1    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libwebp-base              1.4.0                hd590300_0    conda-forge
libxcb                    1.16                 hd590300_0    conda-forge
libxkbcommon              1.0.3                he3ba5ed_0    conda-forge
libxml2                   2.9.14               h74e7548_0  
libzlib                   1.2.13               h4ab18f5_6    conda-forge
lz4-c                     1.9.3                h9c3ff4c_1    conda-forge
matplotlib                3.7.3            py38h578d9bd_0    conda-forge
matplotlib-base           3.7.3            py38h58ed7fa_0    conda-forge
matplotlib-inline         0.1.7              pyhd8ed1ab_0    conda-forge
mkl                       2023.1.0         h213fc3f_46344  
mkl-service               2.4.0            py38h5eee18b_1  
mkl_fft                   1.3.8            py38h5eee18b_0  
mkl_random                1.2.4            py38hdb19cb5_0  
mpmath                    1.3.0                    pypi_0    pypi
multidict                 6.0.5                    pypi_0    pypi
munkres                   1.1.4              pyh9f0ad1d_0    conda-forge
ncurses                   6.4                  h6a678d5_0  
networkx                  3.1                      pypi_0    pypi
nspr                      4.35                 h27087fc_0    conda-forge
nss                       3.100                hca3bf56_0    conda-forge
numpy                     1.24.3           py38hf6e8229_1  
numpy-base                1.24.3           py38h060ed82_1  
nvidia-cublas-cu11        11.10.3.66               pypi_0    pypi
nvidia-cublas-cu12        12.1.3.1                 pypi_0    pypi
nvidia-cuda-cupti-cu12    12.1.105                 pypi_0    pypi
nvidia-cuda-nvrtc-cu11    11.7.99                  pypi_0    pypi
nvidia-cuda-nvrtc-cu12    12.1.105                 pypi_0    pypi
nvidia-cuda-runtime-cu11  11.7.99                  pypi_0    pypi
nvidia-cuda-runtime-cu12  12.1.105                 pypi_0    pypi
nvidia-cudnn-cu11         8.5.0.96                 pypi_0    pypi
nvidia-cudnn-cu12         9.1.0.70                 pypi_0    pypi
nvidia-cufft-cu12         11.0.2.54                pypi_0    pypi
nvidia-curand-cu12        10.3.2.106               pypi_0    pypi
nvidia-cusolver-cu12      11.4.5.107               pypi_0    pypi
nvidia-cusparse-cu12      12.1.0.106               pypi_0    pypi
nvidia-nccl-cu12          2.20.5                   pypi_0    pypi
nvidia-nvjitlink-cu12     12.6.20                  pypi_0    pypi
nvidia-nvtx-cu12          12.1.105                 pypi_0    pypi
olefile                   0.47               pyhd8ed1ab_0    conda-forge
openjpeg                  2.4.0                hb52868f_1    conda-forge
openssl                   3.3.1                h4bc722e_2    conda-forge
packaging                 24.1             py38h06a4308_0  
pandas                    2.0.3            py38h01efb38_1    conda-forge
parso                     0.8.4              pyhd8ed1ab_0    conda-forge
pathtools                 0.1.2                      py_1    conda-forge
patsy                     0.5.6              pyhd8ed1ab_0    conda-forge
pcre2                     10.43                hcad00b1_0    conda-forge
peft                      0.12.0                   pypi_0    pypi
pexpect                   4.9.0              pyhd8ed1ab_0    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    10.4.0                   pypi_0    pypi
pip                       24.2             py38h06a4308_0  
platformdirs              3.10.0           py38h06a4308_0  
pooch                     1.7.0            py38h06a4308_0  
prompt-toolkit            3.0.47             pyha770c72_0    conda-forge
prompt_toolkit            3.0.47               hd8ed1ab_0    conda-forge
protobuf                  3.20.1           py38hfa26641_0    conda-forge
psutil                    6.0.0            py38hfb59056_0    conda-forge
pthread-stubs             0.4               h36c2ea0_1001    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.3              pyhd8ed1ab_0    conda-forge
pyarrow                   17.0.0                   pypi_0    pypi
pygments                  2.18.0             pyhd8ed1ab_0    conda-forge
pyparsing                 3.1.2              pyhd8ed1ab_0    conda-forge
pyqt                      5.15.4           py38hfa26641_0    conda-forge
pyqt5-sip                 12.9.0           py38hfa26641_0    conda-forge
pysocks                   1.7.1            py38h06a4308_0  
python                    3.8.19               h955ad1f_0  
python-dateutil           2.9.0              pyhd8ed1ab_0    conda-forge
python-tzdata             2024.1             pyhd8ed1ab_0    conda-forge
python_abi                3.8                      2_cp38    conda-forge
pytz                      2024.1             pyhd8ed1ab_0    conda-forge
pyyaml                    6.0.2            py38h2019614_0    conda-forge
qt-main                   5.15.2               h327a75a_7  
readline                  8.2                  h5eee18b_0  
regex                     2024.7.24                pypi_0    pypi
requests                  2.32.3           py38h06a4308_0  
safetensors               0.4.4                    pypi_0    pypi
scikit-learn              1.3.0            py38h1128e8f_1  
scipy                     1.10.1           py38hf6e8229_1  
seaborn                   0.13.2               hd8ed1ab_2    conda-forge
seaborn-base              0.13.2             pyhd8ed1ab_2    conda-forge
sentry-sdk                2.13.0             pyhd8ed1ab_0    conda-forge
setproctitle              1.3.3            py38h01eb140_0    conda-forge
setuptools                72.1.0           py38h06a4308_0  
sip                       6.5.1            py38h709712a_2    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
smmap                     5.0.0              pyhd8ed1ab_0    conda-forge
soupsieve                 2.5                pyhd8ed1ab_1    conda-forge
sqlite                    3.45.3               h5eee18b_0  
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
statsmodels               0.14.1           py38h7f0c24c_0    conda-forge
sympy                     1.13.2                   pypi_0    pypi
tbb                       2021.8.0             hdb19cb5_0  
threadpoolctl             3.5.0            py38h2f386ee_0  
tk                        8.6.14               h39e8969_0  
tokenizers                0.19.1                   pypi_0    pypi
toml                      0.10.2             pyhd8ed1ab_0    conda-forge
torch                     1.13.0                   pypi_0    pypi
torchvision               0.14.0                   pypi_0    pypi
tornado                   6.4.1            py38hfb59056_0    conda-forge
tqdm                      4.66.4           py38h2f386ee_0  
traitlets                 5.14.3             pyhd8ed1ab_0    conda-forge
transformers              4.44.0                   pypi_0    pypi
triton                    3.0.0                    pypi_0    pypi
typing_extensions         4.12.2             pyha770c72_0    conda-forge
unicodedata2              15.1.0           py38h01eb140_0    conda-forge
urllib3                   2.2.2            py38h06a4308_0  
wandb                     0.16.6             pyhd8ed1ab_0    conda-forge
wcwidth                   0.2.13             pyhd8ed1ab_0    conda-forge
wheel                     0.43.0           py38h06a4308_0  
xorg-libxau               1.0.11               hd590300_0    conda-forge
xorg-libxdmcp             1.1.3                h7f98852_0    conda-forge
xxhash                    3.5.0                    pypi_0    pypi
xz                        5.4.6                h5eee18b_1  
yaml                      0.2.5                h7f98852_2    conda-forge
yarl                      1.9.4                    pypi_0    pypi
zipp                      3.20.0             pyhd8ed1ab_0    conda-forge
zlib                      1.2.13               h4ab18f5_6    conda-forge
zstd                      1.5.6                ha6fb4c9_0    conda-forge
Free-Dreamer commented 1 month ago

Another error after I fix the above one:

UnboundLocalError: local variable 'in_features' referenced before assignment

in local_lorasym_all.py:583. I believe the author did not test their code before publishing it...

hammoudhasan commented 1 month ago

@Free-Dreamer I can run the code fine. Did you make sure the PEFT version is alright?

The required peft version is 0.5.0 you installed 0.12.0 of course you will get errors.

Do pip install peft==0.5.0 or pip install -r requirements.txt and let me know if that fixes your issue.

Free-Dreamer commented 1 month ago

Hi @hammoudhasan Thanks for your comments. I believe I have tried the correct version of peft. Like what I said,

I follow the instruction to install the environment and try different versions of peft and transformers.

Now I totally follow the instruction to install the environment and make sure peft==0.5.0. I try to run the demo with two scripts.

One is the scripts provided by the repo:

from transformers import AutoModelForSequenceClassification
from LoRASYM_peft.local_peft_model_all import PeftModelForCausalLM_local
from LoRASYM_peft.local_lorasym_all import LoRASYMConfig

model = AutoModelForSequenceClassification.from_pretrained(
        'FacebookAI/roberta-large',
    )

update_rule_dict = para_dict = {"update_A": False, "update_B": True, 
"A_init": "rand", "B_init": "zero"}

lorasym_config = LoRASYMConfig(
                r=16,   
                lora_alpha=32,
                lora_dropout=0.05,
                bias="none",
                modules_to_save=["classifier"],
                update_rule=update_rule_dict,
                task_type="SEQ_CLS",
                )

lora_model = PeftModelForCausalLM_local(model, lorasym_config)

The other follows the configuration in the run_glue_origin_ft.py:

from transformers import AutoModelForSequenceClassification, AutoConfig
from LoRASYM_peft.local_peft_model_all import PeftModelForCausalLM_local
from LoRASYM_peft.local_lorasym_all import LoRASYMConfig

update_rule_dict = para_dict = {"update_A": False, "update_B": True, 
"A_init": "rand", "B_init": "zero"}

config = AutoConfig.from_pretrained(
    'FacebookAI/roberta-large',
    num_labels=2,
    finetuning_task='rte',
    cache_dir='./',
    revision='main',
    token=None,
    trust_remote_code=False,
    )

model = AutoModelForSequenceClassification.from_pretrained(
        'FacebookAI/roberta-large',
        config=config,
        cache_dir='./',
        revision='main',
        token=None,
        trust_remote_code=False,
        ignore_mismatched_sizes=False,
    )

lorasym_config = LoRASYMConfig(
                r=16,   
                lora_alpha=32,
                lora_dropout=0.05,
                bias="none",
                modules_to_save=["classifier"],
                update_rule=update_rule_dict,
                task_type="SEQ_CLS",
                )

lora_model = PeftModelForCausalLM_local(model, lorasym_config)

Unfortunately, however, I can still NOT run either successfully.

You may want to run by yourself, but I will close this issue since I fine other repos now. Thanks!