transformers 从4.26.1 升级至4.27.1 后报错 ModuleNotFoundError: No module named 'transformers_modules.THUDM/chatglm-6b'

#42
by liuhantao - opened

transformers 从4.26.1 升级至4.27.1 后报错 ModuleNotFoundError: No module named 'transformers_modules.THUDM/chatglm-6b'

异常日志如下,请求指导我解决

Explicitly passing a revision is encouraged when loading a model with custom code to ensure no malicious code has been contributed in a newer revision.
2023-04-14 11:56:23.342 Uncaught app exception
Traceback (most recent call last):
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 245, in _get_or_create_cached_value
cached_result = cache.read_result(value_key)
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\streamlit\runtime\caching\cache_resource_api.py", line 447, in read_result
raise CacheKeyNotFoundError()
streamlit.runtime.caching.cache_errors.CacheKeyNotFoundError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 293, in _handle_cache_miss
cached_result = cache.read_result(value_key)
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\streamlit\runtime\caching\cache_resource_api.py", line 447, in read_result
raise CacheKeyNotFoundError()
streamlit.runtime.caching.cache_errors.CacheKeyNotFoundError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 565, in _run_script
exec(code, module.dict)
File "D:\ChatGLM-6B-main\web_demo2.py", line 69, in
st.session_state["state"] = predict(prompt_text, max_length, top_p, temperature, st.session_state["state"])
File "D:\ChatGLM-6B-main\web_demo2.py", line 25, in predict
tokenizer, model = get_model()
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 194, in wrapper
return cached_func(*args, **kwargs)
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 223, in call
return self._get_or_create_cached_value(args, kwargs)
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 248, in _get_or_create_cached_value
return self._handle_cache_miss(cache, value_key, func_args, func_kwargs)
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\streamlit\runtime\caching\cache_utils.py", line 302, in _handle_cache_miss
computed_value = self.info.func(*func_args, **func_kwargs)
File "D:\ChatGLM-6B-main\web_demo2.py", line 14, in get_model
tokenizer = AutoTokenizer.from_pretrained("THUDM/chatglm-6b", trust_remote_code=True)
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\transformers\models\auto\tokenization_auto.py", line 663, in from_pretrained
tokenizer_class = get_class_from_dynamic_module(
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\transformers\dynamic_module_utils.py", line 399, in get_class_from_dynamic_module
return get_class_in_module(class_name, final_module.replace(".py", ""))
File "D:\ChatGLM-6B-main\MyENV\lib\site-packages\transformers\dynamic_module_utils.py", line 177, in get_class_in_module
module = importlib.import_module(module_path)
File "D:\ChatGLM-6B-main\MyENV\lib\importlib_init
.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 992, in _find_and_load_unlocked
File "", line 241, in _call_with_frames_removed
File "", line 1050, in _gcd_import
File "", line 1027, in _find_and_load
File "", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'transformers_modules.THUDM/chatglm-6b'

transformers_modules.jpg

经反复尝试,升级4.27.1以及以上版本后,web_demo2.py、web_demo.py 文件中识别目录由“THUDM/chatglm-6b”,需要更改为"THUDM\chatglm-6b",更改后问题解决。

有条件,我们都是下载离线版本的,都没有这个困扰了。。

Sign up or log in to comment