New Error Everyday, Error Occuring in Jupyter Notebook
It Was Working a Week Ago. .. !Pip Install Torch Transformers Bitsandbytes Accelerate Sqlparse Import Torch from Transformers Import Autotokenizer...
It was working a week ago...
!pip install torch transformers bitsandbytes accelerate sqlparse
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_name = "codellama/CodeLlama-34b-hf"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
trust_remote_code=True,
torch_dtype=torch.float16,
#load_in_8bit=True,
load_in_4bit=True,
device_map="auto",
use_cache=True,
)
This is the model and only 4-bit works.I'm encountering a perplexing issue while working with the transformers library in Python. I'm facing an import-related error that seems to stem from conflicts within the bitsandbytes and triton modules. Specifically, the error message 'module 'importlib._bootstrap' has no attribute 'SourceFileLoader'' is appearing in the traceback.
I suspect the error might be due to conflicts between different library versions or dependencies.
How to resolve this issue and properly handle the imports within the transformers library.?
The error is shown below:
AttributeError Traceback (most recent call last)
File /usr/local/lib/python3.8/dist-packages/transformers/utils/import_utils.py:1353, in _LazyModule._get_module(self, module_name)
1352 try:
-> 1353 return importlib.import_module("." + module_name, self.__name__)
1354 except Exception as e:
File /usr/lib/python3.8/importlib/__init__.py:127, in import_module(name, package)
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
File <frozen importlib._bootstrap>:1014, in _gcd_import(name, package, level)
File <frozen importlib._bootstrap>:991, in _find_and_load(name, import_)
File <frozen importlib._bootstrap>:975, in _find_and_load_unlocked(name, import_)
File <frozen importlib._bootstrap>:671, in _load_unlocked(spec)
File <frozen importlib._bootstrap_external>:848, in exec_module(self, module)
File <frozen importlib._bootstrap>:219, in _call_with_frames_removed(f, *args, **kwds)
File /usr/local/lib/python3.8/dist-packages/transformers/integrations/bitsandbytes.py:11
10 if is_bitsandbytes_available():
---> 11 import bitsandbytes as bnb
12 import torch
File /usr/local/lib/python3.8/dist-packages/bitsandbytes/__init__.py:16
15 from .cextension import COMPILED_WITH_CUDA
---> 16 from .nn import modules
18 if COMPILED_WITH_CUDA:
File /usr/local/lib/python3.8/dist-packages/bitsandbytes/nn/__init__.py:6
5 from .modules import Int8Params, Linear8bitLt, StableEmbedding, Linear4bit, LinearNF4, LinearFP4, Params4bit, OutlierAwareLinear, SwitchBackLinearBnb
----> 6 from .triton_based_modules import SwitchBackLinear, SwitchBackLinearGlobal, SwitchBackLinearVectorwise, StandardLinear
File /usr/local/lib/python3.8/dist-packages/bitsandbytes/nn/triton_based_modules.py:8
6 from bitsandbytes.triton.triton_utils import is_triton_available
----> 8 from bitsandbytes.triton.dequantize_rowwise import dequantize_rowwise
9 from bitsandbytes.triton.quantize_rowwise import quantize_rowwise
File /usr/local/lib/python3.8/dist-packages/bitsandbytes/triton/dequantize_rowwise.py:10
8 else:
---> 10 import triton
11 import triton.language as tl
File /usr/local/lib/python3.8/dist-packages/triton/__init__.py:8
4 # ---------------------------------------
5 # Note: import order is significant here.
6
7 # submodules
----> 8 from .runtime import (
9 autotune,
10 Config,
11 heuristics,
12 JITFunction,
13 KernelInterface,
14 reinterpret,
15 TensorWrapper,
16 OutOfResources,
17 MockTensor,
18 )
19 from .runtime.jit import jit
File /usr/local/lib/python3.8/dist-packages/triton/runtime/__init__.py:1
----> 1 from .autotuner import (Autotuner, Config, Heuristics, OutOfResources, autotune,
2 heuristics)
3 from .driver import driver
File /usr/local/lib/python3.8/dist-packages/triton/runtime/autotuner.py:8
7 from ..testing import do_bench
----> 8 from .jit import KernelInterface
11 class OutOfResources(Exception):
File /usr/local/lib/python3.8/dist-packages/triton/runtime/jit.py:14
11 from typing import (Callable, Generic, Iterable, List, Optional, TypeVar, Union, cast,
12 overload)
---> 14 from ..common.backend import get_backend, path_to_ptxas
16 TRITON_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
File /usr/local/lib/python3.8/dist-packages/triton/common/__init__.py:1
----> 1 from .build import _build, cuda_include_dir, libcuda_dirs
3 __all__ = ["_build", "libcuda_dirs", "cuda_include_dir"]
File /usr/local/lib/python3.8/dist-packages/triton/common/build.py:10
8 import sysconfig
---> 10 import setuptools
13 # TODO: is_hip shouldn't be here
File /usr/local/lib/python3.8/dist-packages/setuptools/__init__.py:12
11 import setuptools.version
---> 12 from setuptools.extension import Extension
13 from setuptools.dist import Distribution, Feature, _get_unpatched
File /usr/local/lib/python3.8/dist-packages/setuptools/extension.py:7
5 import distutils.extension
----> 7 from setuptools.dist import _get_unpatched
9 _Extension = _get_unpatched(distutils.core.Extension)
File /usr/local/lib/python3.8/dist-packages/setuptools/dist.py:16
15 from setuptools.compat import numeric_types, basestring
---> 16 import pkg_resources
18 def _get_unpatched(cls):
File /usr/local/lib/python3.8/dist-packages/pkg_resources.py:1479
1478 if importlib_bootstrap is not None:
-> 1479 register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
1482 class EmptyProvider(NullProvider):
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
The above exception was the direct cause of the following exception:
RuntimeError Traceback (most recent call last)
Cell In [9], line 3
1 model_name = "codellama/CodeLlama-34b-hf"
2 tokenizer = AutoTokenizer.from_pretrained(model_name)
----> 3 model = AutoModelForCausalLM.from_pretrained(
4 model_name,
5 trust_remote_code=True,
6 torch_dtype=torch.float16,
7 #load_in_8bit=True,
8 load_in_4bit=True,
9 device_map="auto",
10 use_cache=True,
11 )
File /usr/local/lib/python3.8/dist-packages/transformers/models/auto/auto_factory.py:566, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
564 elif type(config) in cls._model_mapping.keys():
565 model_class = _get_model_class(config, cls._model_mapping)
--> 566 return model_class.from_pretrained(
567 pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
568 )
569 raise ValueError(
570 f"Unrecognized configuration class {config.__class__} for this kind of AutoModel: {cls.__name__}.\n"
571 f"Model type should be one of {', '.join(c.__name__ for c in cls._model_mapping.keys())}."
572 )
File /usr/local/lib/python3.8/dist-packages/transformers/modeling_utils.py:3250, in PreTrainedModel.from_pretrained(cls, pretrained_model_name_or_path, config, cache_dir, ignore_mismatched_sizes, force_download, local_files_only, token, revision, use_safetensors, *model_args, **kwargs)
3247 keep_in_fp32_modules = []
3249 if load_in_8bit or load_in_4bit:
-> 3250 from .integrations import get_keys_to_not_convert, replace_with_bnb_linear
3252 llm_int8_skip_modules = quantization_config.llm_int8_skip_modules
3253 load_in_8bit_fp32_cpu_offload = quantization_config.llm_int8_enable_fp32_cpu_offload
File <frozen importlib._bootstrap>:1039, in _handle_fromlist(module, fromlist, import_, recursive)
File /usr/local/lib/python3.8/dist-packages/transformers/utils/import_utils.py:1343, in _LazyModule.__getattr__(self, name)
1341 value = self._get_module(name)
1342 elif name in self._class_to_module.keys():
-> 1343 module = self._get_module(self._class_to_module[name])
1344 value = getattr(module, name)
1345 else:
File /usr/local/lib/python3.8/dist-packages/transformers/utils/import_utils.py:1355, in _LazyModule._get_module(self, module_name)
1353 return importlib.import_module("." + module_name, self.__name__)
1354 except Exception as e:
-> 1355 raise RuntimeError(
1356 f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
1357 f" traceback):\n{e}"
1358 ) from e
RuntimeError: Failed to import transformers.integrations.bitsandbytes because of the following error (look up to see its traceback):
module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
Have tried reinstalling torch,checked python version,is 3.8.1 so is compatible....None of it seemed to make a difference.