huggingface / optimum-neuron

Easy, fast and very cheap training and inference on AWS Trainium and Inferentia chips.
Apache License 2.0
176 stars 51 forks source link

Inf1: optimum neuron inference tests failing with import errors from transformers.utils and huggingface_hub #573

Closed musunita closed 2 months ago

musunita commented 2 months ago

System Info

Platform : U20 INF1
Instance type:  Inf1.6xlarge

Versions:
python 3.8

optimum-cli env

Copy-and-paste the text below in your GitHub issue:

Platform:

- Platform: Linux-5.15.0-1057-aws-x86_64-with-glibc2.29
- Python version: 3.8.10

Python packages:

- `optimum-neuron` version: 0.0.21
- `neuron-sdk` version: 2.18.0
- `optimum` version: 1.18.1
- `transformers` version: 4.36.2
- `huggingface_hub` version: 0.22.2
- `torch` version: 1.13.1+cu117
- `dmlc-tvm` version: 1.19.0.0+0
- `neuron-cc` version: 1.22.0.0+d4b4f5311
- `torch-neuron` version: 1.13.1.2.9.74.0

Neuron Driver:

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

aws-neuronx-collectives/now 2.20.22.0-c101c322e amd64 [installed,local]
aws-neuronx-devtools/now 2.17.1.0 amd64 [installed,local]
aws-neuronx-dkms/now 2.16.7.0 amd64 [installed,local]
aws-neuronx-oci-hook/now 2.3.0.0 amd64 [installed,local]
aws-neuronx-runtime-lib/now 2.20.22.0-1b3ca6425 amd64 [installed,local]
aws-neuronx-tools/now 2.17.1.0 amd64 [installed,local]

(aws_neuron_venv) ubuntu@ip-10-4-210-72:~/optimum-neuron$ pip list | grep "parameterized" parameterized 0.9.0


### Who can help?

@dacorvo, @JingyaHuang

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction (minimal, reproducible, runnable)

Reproducible steps:
Launch Inf1.6xlarge instance
Install latest neuorn bits.

Use v0.0.21 version of the release for optimum-neuron.
pip install optimum-neuron
git clone --depth 1 --branch v0.0.21 https://github.com/huggingface/optimum-neuron.git
cd optimum-neuron/examples/translation
pip install -r requirements.txt
pytest -m is_inferentia_test tests

Error log:

================================================================================ test session starts ================================================================================= platform linux -- Python 3.8.10, pytest-8.1.1, pluggy-1.4.0 rootdir: /home/ubuntu/optimum-neuron configfile: pyproject.toml plugins: remotedata-0.4.1, xdist-3.5.0, timeout-2.3.1 collected 0 items / 19 errors

======================================================================================= ERRORS ======================================================================================= _ ERROR collecting tests/cache/test_neuronxcache.py ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/cache/test_neuronx_cache.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/cache/test_neuronx_cache.py:29: in from optimum.neuron import ( optimum/neuron/init.py:18: in from transformers.utils import _LazyModule E ImportError: cannot import name '_LazyModule' from 'transformers.utils' (/home/ubuntu/.local/lib/python3.8/site-packages/transformers/utils/init.py) _____ ERROR collecting tests/cli/test_export_cli.py ____ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/cli/test_export_cli.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/cli/test_export_cli.py:20: in from optimum.exporters.neuron.model_configs import * # noqa: F403 optimum/exporters/neuron/init.py:17: in from transformers.utils import _LazyModule E ImportError: cannot import name '_LazyModule' from 'transformers.utils' (/home/ubuntu/.local/lib/python3.8/site-packages/transformers/utils/init.py) _ ERROR collecting tests/cli/test_export_decoder_cli.py ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/cli/test_export_decoder_cli.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/cli/test_export_decoder_cli.py:7: in from optimum.neuron.utils.testing_utils import is_inferentia_test, requires_neuronx optimum/neuron/init.py:18: in from transformers.utils import _LazyModule E ImportError: cannot import name '_LazyModule' from 'transformers.utils' (/home/ubuntu/.local/lib/python3.8/site-packages/transformers/utils/init.py) ____ ERROR collecting tests/cli/test_neuron_cachecli.py ____ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/cli/test_neuron_cache_cli.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/cli/test_neuron_cache_cli.py:24: in from huggingface_hub import HfApi, create_repo, delete_repo E ImportError: cannot import name 'create_repo' from 'huggingface_hub' (/home/ubuntu/.local/lib/python3.8/site-packages/huggingfacehub/init.py) ____ ERROR collecting tests/distributed/test_common.py __ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/distributed/test_common.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/distributed/test_common.py:21: in import safetensors E ModuleNotFoundError: No module named 'safetensors' __ ERROR collecting tests/distributed/test_model_parallelization.py __ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/distributed/test_model_parallelization.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/distributed/test_model_parallelization.py:23: in from transformers import AutoTokenizer, LlamaForCausalLM E ImportError: cannot import name 'LlamaForCausalLM' from 'transformers' (unknown location) ____ ERROR collecting tests/distributed/testtraining.py ____ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/distributed/test_training.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/distributed/test_training.py:21: in from datasets import load_dataset E ModuleNotFoundError: No module named 'datasets' __ ERROR collecting tests/distributed/test_utils.py __ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/distributed/test_utils.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/distributed/test_utils.py:24: in from safetensors.torch import save_file E ModuleNotFoundError: No module named 'safetensors' __ ERROR collecting tests/exporters/test_export.py _____ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/exporters/test_export.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/exporters/test_export.py:24: in from parameterized import parameterized E ModuleNotFoundError: No module named 'parameterized' ___ ERROR collecting tests/generation __ /usr/lib/python3.8/importlib/init.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level)

:1014: in _gcd_import ??? :991: in _find_and_load ??? :975: in _find_and_load_unlocked ??? :671: in _load_unlocked ??? ../.local/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:178: in exec_module exec(co, module.__dict__) tests/generation/conftest.py:20: in from optimum.neuron import NeuronModelForCausalLM, NeuronModelForSeq2SeqLM optimum/neuron/__init__.py:18: in from transformers.utils import _LazyModule E ImportError: cannot import name '_LazyModule' from 'transformers.utils' (/home/ubuntu/.local/lib/python3.8/site-packages/transformers/utils/__init__.py) _________________________________________________________________ ERROR collecting tests/inference/test_modeling.py __________________________________________________________________ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/inference/test_modeling.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/inference/test_modeling.py:23: in from parameterized import parameterized E ModuleNotFoundError: No module named 'parameterized' _________________________________________________________ ERROR collecting tests/inference/test_stable_diffusion_pipeline.py _________________________________________________________ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/inference/test_stable_diffusion_pipeline.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/inference/test_stable_diffusion_pipeline.py:20: in from parameterized import parameterized E ModuleNotFoundError: No module named 'parameterized' __________________________________________________________________________ ERROR collecting tests/pipelines __________________________________________________________________________ /usr/lib/python3.8/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) :1014: in _gcd_import ??? :991: in _find_and_load ??? :975: in _find_and_load_unlocked ??? :671: in _load_unlocked ??? ../.local/lib/python3.8/site-packages/_pytest/assertion/rewrite.py:178: in exec_module exec(co, module.__dict__) tests/pipelines/conftest.py:20: in from optimum.neuron import NeuronModelForCausalLM optimum/neuron/__init__.py:18: in from transformers.utils import _LazyModule E ImportError: cannot import name '_LazyModule' from 'transformers.utils' (/home/ubuntu/.local/lib/python3.8/site-packages/transformers/utils/__init__.py) _____________________________________________________________________ ERROR collecting tests/test_cache_utils.py _____________________________________________________________________ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/test_cache_utils.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/test_cache_utils.py:26: in from huggingface_hub import create_repo, delete_repo, get_token, login E ImportError: cannot import name 'create_repo' from 'huggingface_hub' (/home/ubuntu/.local/lib/python3.8/site-packages/huggingface_hub/__init__.py) ______________________________________________________________________ ERROR collecting tests/test_examples.py _______________________________________________________________________ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/test_examples.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/test_examples.py:27: in from huggingface_hub import get_token E ImportError: cannot import name 'get_token' from 'huggingface_hub' (/home/ubuntu/.local/lib/python3.8/site-packages/huggingface_hub/__init__.py) ______________________________________________________________________ ERROR collecting tests/test_generate.py _______________________________________________________________________ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/test_generate.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/test_generate.py:6: in from parameterized import parameterized E ModuleNotFoundError: No module named 'parameterized' _______________________________________________________________________ ERROR collecting tests/test_runner.py ________________________________________________________________________ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/test_runner.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/test_runner.py:20: in from huggingface_hub import get_token, login E ImportError: cannot import name 'get_token' from 'huggingface_hub' (/home/ubuntu/.local/lib/python3.8/site-packages/huggingface_hub/__init__.py) ______________________________________________________________________ ERROR collecting tests/test_trainers.py _______________________________________________________________________ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/test_trainers.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/test_trainers.py:28: in from huggingface_hub import HfApi, delete_repo E ImportError: cannot import name 'delete_repo' from 'huggingface_hub' (/home/ubuntu/.local/lib/python3.8/site-packages/huggingface_hub/__init__.py) ________________________________________________________________________ ERROR collecting tests/test_utils.py ________________________________________________________________________ ImportError while importing test module '/home/ubuntu/optimum-neuron/tests/test_utils.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: /usr/lib/python3.8/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) tests/test_utils.py:24: in from optimum.neuron.accelerate.accelerator import MODEL_PATCHING_SPECS optimum/neuron/__init__.py:18: in from transformers.utils import _LazyModule E ImportError: cannot import name '_LazyModule' from 'transformers.utils' (/home/ubuntu/.local/lib/python3.8/site-packages/transformers/utils/__init__.py) ============================================================================== short test summary info =============================================================================== ERROR tests/cache/test_neuronx_cache.py ERROR tests/cli/test_export_cli.py ERROR tests/cli/test_export_decoder_cli.py ERROR tests/cli/test_neuron_cache_cli.py ERROR tests/distributed/test_common.py ERROR tests/distributed/test_model_parallelization.py ERROR tests/distributed/test_training.py ERROR tests/distributed/test_utils.py ERROR tests/exporters/test_export.py ERROR tests/generation - ImportError: cannot import name '_LazyModule' from 'transformers.utils' (/home/ubuntu/.local/lib/python3.8/site-packages/transformers/utils/__init__.py) ERROR tests/inference/test_modeling.py ERROR tests/inference/test_stable_diffusion_pipeline.py ERROR tests/pipelines - ImportError: cannot import name '_LazyModule' from 'transformers.utils' (/home/ubuntu/.local/lib/python3.8/site-packages/transformers/utils/__init__.py) ERROR tests/test_cache_utils.py ERROR tests/test_examples.py ERROR tests/test_generate.py ERROR tests/test_runner.py ERROR tests/test_trainers.py ERROR tests/test_utils.py !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 19 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ================================================================================= 19 errors in 1.90s ============== ``` ``` [Tests in Optimum Neuron (3) (3).pdf](https://github.com/huggingface/optimum-neuron/files/15045870/Tests.in.Optimum.Neuron.3.3.pdf) ``` ### Expected behavior Expected to optimum-neuron tests to pass on Inf1.
JingyaHuang commented 2 months ago

Hi @musunita,

It seems to be an issue from the setup. If you are testing for Optimum Neuron v0.0.21, could you try the following under a clean environment?

git clone --depth 1 --branch v0.0.21 https://github.com/huggingface/optimum-neuron.git
pip install .[tests]

image

musunita commented 2 months ago

Thanks for the quick reply. I am not seeing previous error. New error is as below.


        revision: Optional[str] = None,
        use_auth_token: Union[bool, str] = True,
        endpoint: Optional[str] = None,
    ) -> str:
        if isinstance(use_auth_token, str):
            huggingface_token = use_auth_token
        elif use_auth_token:
            huggingface_token = HfFolder.get_token()
        else:
>           raise ValueError("You need to provide `use_auth_token` to be able to push to the hub")
E           ValueError: You need to provide `use_auth_token` to be able to push to the hub

optimum/neuron/modeling_base.py:374: ValueError

Where to specify the token in the test?

JingyaHuang commented 2 months ago

Could you point me to the test you are facing this error?

You could specify the HF token like the following:

HF_TOKEN=xxxxxxx python -m pytest -m is_inferentia_test tests

But need to see if the test is pushing to the staging hub or the real HF hub.

musunita commented 2 months ago

Repo errors are listed in the attached log. There are multiple repo errors even with write token. output3inf1.txt .

JingyaHuang commented 2 months ago

Hi @musunita thanks for the log. It's due to the fact that your token doesn't have write access to the optimum org. We have push_to_hub by default in our tests to ensure the test models under our org are always up to date, it's not necessary for users outside the org to launch the tests.

PR #585 shall make it easier for you to launch tests.