You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = r"C:\Users\zjian\HuatuoGPT-o1-7B"
从本地路径加载模型和分词器
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(model_path)
input_text = "How to stop a cough?"
messages = [{"role": "user", "content": input_text}]
###############
7b's problem
###############
KeyError Traceback (most recent call last)
Cell In[4], line 7
4 model_path = r"C:\Users\zjian\HuatuoGPT-o1-7B"
6 # 从本地路径加载模型和分词器
----> 7 model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
8 tokenizer = AutoTokenizer.from_pretrained(model_path)
10 input_text = "How to stop a cough?"
File ~.conda\envs\modelscope\lib\site-packages\transformers\models\auto\auto_factory.py:456, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
453 if kwargs.get("torch_dtype", None) == "auto":
454 _ = kwargs.pop("torch_dtype")
--> 456 config, kwargs = AutoConfig.from_pretrained(
457 pretrained_model_name_or_path,
458 return_unused_kwargs=True,
459 trust_remote_code=trust_remote_code,
460 **hub_kwargs,
461 **kwargs,
462 )
464 # if torch_dtype=auto was passed here, ensure to pass it on
465 if kwargs_orig.get("torch_dtype", None) == "auto":
File ~.conda\envs\modelscope\lib\site-packages\transformers\models\auto\configuration_auto.py:957, in AutoConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
955 return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
956 elif "model_type" in config_dict:
--> 957 config_class = CONFIG_MAPPING[config_dict["model_type"]]
958 return config_class.from_dict(config_dict, **unused_kwargs)
959 else:
960 # Fallback: use pattern matching on the string.
961 # We go from longer names to shorter names to catch roberta before bert (for instance)
File ~.conda\envs\modelscope\lib\site-packages\transformers\models\auto\configuration_auto.py:671, in _LazyConfigMapping.getitem(self, key)
669 return self._extra_content[key]
670 if key not in self._mapping:
--> 671 raise KeyError(key)
672 value = self._mapping[key]
673 module_name = model_type_to_module_name(key)
KeyError: 'qwen2'
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = r"C:\Users\zjian\HuatuoGPT-o1-8B"
从本地路径加载模型和分词器
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(model_path)
input_text = "How to stop a cough?"
messages = [{"role": "user", "content": input_text}]
###############
8b's problem
###############
Loading checkpoint shards: 0%| | 0/4 [00:00<?, ?it/s]
ValueError Traceback (most recent call last)
Cell In[5], line 7
4 model_path = r"C:\Users\zjian\HuatuoGPT-o1-8B"
6 # 从本地路径加载模型和分词器
----> 7 model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
8 tokenizer = AutoTokenizer.from_pretrained(model_path)
10 input_text = "How to stop a cough?"
File ~.conda\envs\modelscope\lib\site-packages\transformers\models\auto\auto_factory.py:484, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
482 elif type(config) in cls._model_mapping.keys():
483 model_class = _get_model_class(config, cls._model_mapping)
--> 484 return model_class.from_pretrained(
485 pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
486 )
487 raise ValueError(
488 f"Unrecognized configuration class {config.class} for this kind of AutoModel: {cls.name}.\n"
489 f"Model type should be one of {', '.join(c.name for c in cls._model_mapping.keys())}."
490 )
File ~.conda\envs\modelscope\lib\site-packages\transformers\modeling_utils.py:720, in _load_state_dict_into_meta_model(model, state_dict, loaded_state_dict_keys, start_prefix, expected_keys, device_map, offload_folder, offload_index, state_dict_folder, state_dict_index, dtype, is_quantized, is_safetensors, keep_in_fp32_modules)
717 state_dict_index = offload_weight(param, param_name, state_dict_folder, state_dict_index)
718 elif not is_quantized:
719 # For backward compatibility with older versions of accelerate
--> 720 set_module_tensor_to_device(model, param_name, param_device, **set_module_kwargs)
721 else:
722 if param.dtype == torch.int8 and param_name.replace("weight", "SCB") in state_dict.keys():
File ~.conda\envs\modelscope\lib\site-packages\accelerate\utils\modeling.py:285, in set_module_tensor_to_device(module, tensor_name, device, value, dtype, fp16_statistics)
283 if value is not None:
284 if old_value.shape != value.shape:
--> 285 raise ValueError(
286 f'Trying to set a tensor of shape {value.shape} in "{tensor_name}" (which has shape {old_value.shape}), this look incorrect.'
287 )
289 if dtype is None:
290 # For compatibility with PyTorch load_state_dict which converts state dict dtype to existing dtype in model
291 value = value.to(old_value.dtype)
ValueError: Trying to set a tensor of shape torch.Size([1024, 4096]) in "weight" (which has shape torch.Size([4096, 4096])), this look incorrect.
The text was updated successfully, but these errors were encountered:
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = r"C:\Users\zjian\HuatuoGPT-o1-7B"
从本地路径加载模型和分词器
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(model_path)
input_text = "How to stop a cough?"
messages = [{"role": "user", "content": input_text}]
###############
7b's problem
###############
KeyError Traceback (most recent call last)
Cell In[4], line 7
4 model_path = r"C:\Users\zjian\HuatuoGPT-o1-7B"
6 # 从本地路径加载模型和分词器
----> 7 model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
8 tokenizer = AutoTokenizer.from_pretrained(model_path)
10 input_text = "How to stop a cough?"
File ~.conda\envs\modelscope\lib\site-packages\transformers\models\auto\auto_factory.py:456, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
453 if kwargs.get("torch_dtype", None) == "auto":
454 _ = kwargs.pop("torch_dtype")
--> 456 config, kwargs = AutoConfig.from_pretrained(
457 pretrained_model_name_or_path,
458 return_unused_kwargs=True,
459 trust_remote_code=trust_remote_code,
460 **hub_kwargs,
461 **kwargs,
462 )
464 # if torch_dtype=auto was passed here, ensure to pass it on
465 if kwargs_orig.get("torch_dtype", None) == "auto":
File ~.conda\envs\modelscope\lib\site-packages\transformers\models\auto\configuration_auto.py:957, in AutoConfig.from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
955 return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
956 elif "model_type" in config_dict:
--> 957 config_class = CONFIG_MAPPING[config_dict["model_type"]]
958 return config_class.from_dict(config_dict, **unused_kwargs)
959 else:
960 # Fallback: use pattern matching on the string.
961 # We go from longer names to shorter names to catch roberta before bert (for instance)
File ~.conda\envs\modelscope\lib\site-packages\transformers\models\auto\configuration_auto.py:671, in _LazyConfigMapping.getitem(self, key)
669 return self._extra_content[key]
670 if key not in self._mapping:
--> 671 raise KeyError(key)
672 value = self._mapping[key]
673 module_name = model_type_to_module_name(key)
KeyError: 'qwen2'
from transformers import AutoModelForCausalLM, AutoTokenizer
model_path = r"C:\Users\zjian\HuatuoGPT-o1-8B"
从本地路径加载模型和分词器
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(model_path)
input_text = "How to stop a cough?"
messages = [{"role": "user", "content": input_text}]
###############
8b's problem
###############
Loading checkpoint shards: 0%| | 0/4 [00:00<?, ?it/s]
ValueError Traceback (most recent call last)
Cell In[5], line 7
4 model_path = r"C:\Users\zjian\HuatuoGPT-o1-8B"
6 # 从本地路径加载模型和分词器
----> 7 model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype="auto", device_map="auto")
8 tokenizer = AutoTokenizer.from_pretrained(model_path)
10 input_text = "How to stop a cough?"
File ~.conda\envs\modelscope\lib\site-packages\transformers\models\auto\auto_factory.py:484, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
482 elif type(config) in cls._model_mapping.keys():
483 model_class = _get_model_class(config, cls._model_mapping)
--> 484 return model_class.from_pretrained(
485 pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
486 )
487 raise ValueError(
488 f"Unrecognized configuration class {config.class} for this kind of AutoModel: {cls.name}.\n"
489 f"Model type should be one of {', '.join(c.name for c in cls._model_mapping.keys())}."
490 )
File ~.conda\envs\modelscope\lib\site-packages\transformers\modeling_utils.py:2881, in PreTrainedModel.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
2871 if dtype_orig is not None:
2872 torch.set_default_dtype(dtype_orig)
2874 (
2875 model,
2876 missing_keys,
2877 unexpected_keys,
2878 mismatched_keys,
2879 offload_index,
2880 error_msgs,
-> 2881 ) = cls._load_pretrained_model(
2882 model,
2883 state_dict,
2884 loaded_state_dict_keys, # XXX: rename?
2885 resolved_archive_file,
2886 pretrained_model_name_or_path,
2887 ignore_mismatched_sizes=ignore_mismatched_sizes,
2888 sharded_metadata=sharded_metadata,
2889 _fast_init=_fast_init,
2890 low_cpu_mem_usage=low_cpu_mem_usage,
2891 device_map=device_map,
2892 offload_folder=offload_folder,
2893 offload_state_dict=offload_state_dict,
2894 dtype=torch_dtype,
2895 is_quantized=(load_in_8bit or load_in_4bit),
2896 keep_in_fp32_modules=keep_in_fp32_modules,
2897 )
2899 model.is_loaded_in_4bit = load_in_4bit
2900 model.is_loaded_in_8bit = load_in_8bit
File ~.conda\envs\modelscope\lib\site-packages\transformers\modeling_utils.py:3228, in PreTrainedModel._load_pretrained_model(cls, model, state_dict, loaded_keys, resolved_archive_file, pretrained_model_name_or_path, ignore_mismatched_sizes, sharded_metadata, _fast_init, low_cpu_mem_usage, device_map, offload_folder, offload_state_dict, dtype, is_quantized, keep_in_fp32_modules)
3218 mismatched_keys += _find_mismatched_keys(
3219 state_dict,
3220 model_state_dict,
(...)
3224 ignore_mismatched_sizes,
3225 )
3227 if low_cpu_mem_usage:
-> 3228 new_error_msgs, offload_index, state_dict_index = _load_state_dict_into_meta_model(
3229 model_to_load,
3230 state_dict,
3231 loaded_keys,
3232 start_prefix,
3233 expected_keys,
3234 device_map=device_map,
3235 offload_folder=offload_folder,
3236 offload_index=offload_index,
3237 state_dict_folder=state_dict_folder,
3238 state_dict_index=state_dict_index,
3239 dtype=dtype,
3240 is_quantized=is_quantized,
3241 is_safetensors=is_safetensors,
3242 keep_in_fp32_modules=keep_in_fp32_modules,
3243 )
3244 error_msgs += new_error_msgs
3245 else:
File ~.conda\envs\modelscope\lib\site-packages\transformers\modeling_utils.py:720, in _load_state_dict_into_meta_model(model, state_dict, loaded_state_dict_keys, start_prefix, expected_keys, device_map, offload_folder, offload_index, state_dict_folder, state_dict_index, dtype, is_quantized, is_safetensors, keep_in_fp32_modules)
717 state_dict_index = offload_weight(param, param_name, state_dict_folder, state_dict_index)
718 elif not is_quantized:
719 # For backward compatibility with older versions of
accelerate
--> 720 set_module_tensor_to_device(model, param_name, param_device, **set_module_kwargs)
721 else:
722 if param.dtype == torch.int8 and param_name.replace("weight", "SCB") in state_dict.keys():
File ~.conda\envs\modelscope\lib\site-packages\accelerate\utils\modeling.py:285, in set_module_tensor_to_device(module, tensor_name, device, value, dtype, fp16_statistics)
283 if value is not None:
284 if old_value.shape != value.shape:
--> 285 raise ValueError(
286 f'Trying to set a tensor of shape {value.shape} in "{tensor_name}" (which has shape {old_value.shape}), this look incorrect.'
287 )
289 if dtype is None:
290 # For compatibility with PyTorch load_state_dict which converts state dict dtype to existing dtype in model
291 value = value.to(old_value.dtype)
ValueError: Trying to set a tensor of shape torch.Size([1024, 4096]) in "weight" (which has shape torch.Size([4096, 4096])), this look incorrect.
The text was updated successfully, but these errors were encountered: