Repository navigation
Description
To my knowledge, the latest patch issued should have fixed this bug, but unfortunately it is still here.
Here's the code I used to load the model:
llm_model, tokenizer = FastLanguageModel.from_pretrained(
model_name = f"{model_name}",
max_seq_length = max_seq_length,
dtype = dtype,
load_in_4bit = load_in_4bit,
token = "hf_TOKEN", # use one if using gated models like meta-llama/Llama-2-7b-hf
)
And here's the entire error trace:
ValueError Traceback (most recent call last)
Cell In[8], line 1
----> 1 loadModel("unsloth/Mistral-Small-24B-Instruct-2501-bnb-4bit")
Cell In[6], line 29, in loadModel(model_name)
27 global llm_model, tokenizer
28 print(f'Load model {model_name}')
---> 29 llm_model, tokenizer = FastLanguageModel.from_pretrained(
30 model_name = f"{model_name}",
31 max_seq_length = max_seq_length,
32 dtype = dtype,
33 load_in_4bit = load_in_4bit,
34 token = "hf_TOKEN", # use one if using gated models like meta-llama/Llama-2-7b-hf
35 )
36 EOS_TOKEN = tokenizer.eos_token
File /usr/local/lib/python3.10/dist-packages/unsloth/models/loader.py:258, in FastLanguageModel.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, token, device_map, rope_scaling, fix_tokenizer, trust_remote_code, use_gradient_checkpointing, resize_model_vocab, revision, use_exact_model_name, *args, **kwargs)
255 tokenizer_name = None
256 pass
--> 258 model, tokenizer = dispatch_model.from_pretrained(
259 model_name = model_name,
260 max_seq_length = max_seq_length,
261 dtype = _get_dtype(dtype),
262 load_in_4bit = load_in_4bit,
263 token = token,
264 device_map = device_map,
265 rope_scaling = rope_scaling,
266 fix_tokenizer = fix_tokenizer,
267 model_patcher = dispatch_model,
268 tokenizer_name = tokenizer_name,
269 trust_remote_code = trust_remote_code,
270 revision = revision if not is_peft else None,
271 *args, **kwargs,
272 )
274 if resize_model_vocab is not None:
275 model.resize_token_embeddings(resize_model_vocab)
File /usr/local/lib/python3.10/dist-packages/unsloth/models/mistral.py:348, in FastMistralModel.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, token, device_map, rope_scaling, fix_tokenizer, model_patcher, tokenizer_name, trust_remote_code, **kwargs)
333 @staticmethod
334 def from_pretrained(
335 model_name = "unsloth/mistral-7b-bnb-4bit",
(...)
346 **kwargs,
347 ):
--> 348 return FastLlamaModel.from_pretrained(
349 model_name = model_name,
350 max_seq_length = max_seq_length,
351 dtype = dtype,
352 load_in_4bit = load_in_4bit,
353 token = token,
354 device_map = device_map,
355 rope_scaling = rope_scaling,
356 fix_tokenizer = fix_tokenizer,
357 model_patcher = FastMistralModel,
358 tokenizer_name = tokenizer_name,
359 trust_remote_code = trust_remote_code,
360 **kwargs,
361 )
File /usr/local/lib/python3.10/dist-packages/unsloth/models/llama.py:1691, in FastLlamaModel.from_pretrained(model_name, max_seq_length, dtype, load_in_4bit, token, device_map, rope_scaling, fix_tokenizer, model_patcher, tokenizer_name, trust_remote_code, **kwargs)
1688 # Cannot be None, since HF now checks for the config
1689 if load_in_4bit: kwargs["quantization_config"] = bnb_config
-> 1691 model = AutoModelForCausalLM.from_pretrained(
1692 model_name,
1693 device_map = device_map,
1694 torch_dtype = dtype,
1695 # quantization_config = bnb_config,
1696 token = token,
1697 max_position_embeddings = max_position_embeddings,
1698 trust_remote_code = trust_remote_code,
1699 attn_implementation = "eager",
1700 **kwargs,
1701 )
1702 # Return old flag
1703 os.environ["HF_HUB_ENABLE_HF_TRANSFER"] = old_hf_transfer
File /usr/local/lib/python3.10/dist-packages/transformers/models/auto/auto_factory.py:564, in _BaseAutoModelClass.from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs)
562 elif type(config) in cls._model_mapping.keys():
563 model_class = _get_model_class(config, cls._model_mapping)
--> 564 return model_class.from_pretrained(
565 pretrained_model_name_or_path, *model_args, config=config, **hub_kwargs, **kwargs
566 )
567 raise ValueError(
568 f"Unrecognized configuration class {config.class} for this kind of AutoModel: {cls.name}.\n"
569 f"Model type should be one of {', '.join(c.name for c in cls._model_mapping.keys())}."
570 )
File /usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py:4245, 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, weights_only, *model_args, **kwargs)
4235 load_contexts.append(tp_device)
4237 with ContextManagers(load_contexts):
4238 (
4239 model,
4240 missing_keys,
4241 unexpected_keys,
4242 mismatched_keys,
4243 offload_index,
4244 error_msgs,
-> 4245 ) = cls._load_pretrained_model(
4246 model,
4247 state_dict,
4248 loaded_state_dict_keys, # XXX: rename?
4249 resolved_archive_file,
4250 pretrained_model_name_or_path,
4251 ignore_mismatched_sizes=ignore_mismatched_sizes,
4252 sharded_metadata=sharded_metadata,
4253 _fast_init=_fast_init,
4254 low_cpu_mem_usage=low_cpu_mem_usage,
4255 device_map=device_map,
4256 offload_folder=offload_folder,
4257 offload_state_dict=offload_state_dict,
4258 dtype=torch_dtype,
4259 hf_quantizer=hf_quantizer,
4260 keep_in_fp32_modules=keep_in_fp32_modules,
4261 gguf_path=gguf_path,
4262 weights_only=weights_only,
4263 )
4265 # make sure token embedding weights are still tied if needed
4266 model.tie_weights()
File /usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py:4815, 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, hf_quantizer, keep_in_fp32_modules, gguf_path, weights_only)
4813 else:
4814 fixed_state_dict = cls._fix_state_dict_keys_on_load(state_dict)
-> 4815 new_error_msgs, offload_index, state_dict_index = _load_state_dict_into_meta_model(
4816 model_to_load,
4817 fixed_state_dict,
4818 start_prefix,
4819 expected_keys,
4820 device_map=device_map,
4821 offload_folder=offload_folder,
4822 offload_index=offload_index,
4823 state_dict_folder=state_dict_folder,
4824 state_dict_index=state_dict_index,
4825 dtype=dtype,
4826 hf_quantizer=hf_quantizer,
4827 is_safetensors=is_safetensors,
4828 keep_in_fp32_modules=keep_in_fp32_modules,
4829 unexpected_keys=unexpected_keys,
4830 )
4831 error_msgs += new_error_msgs
4832 else:
4833 # Sharded checkpoint or whole but low_cpu_mem_usage==True
File /usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py:875, in _load_state_dict_into_meta_model(model, state_dict, start_prefix, expected_keys, device_map, offload_folder, offload_index, state_dict_folder, state_dict_index, dtype, hf_quantizer, is_safetensors, keep_in_fp32_modules, unexpected_keys, pretrained_model_name_or_path)
873 set_module_tensor_to_device(model, param_name, param_device, **set_module_kwargs)
874 else:
--> 875 hf_quantizer.create_quantized_param(model, param, param_name, param_device, state_dict, unexpected_keys)
876 # For quantized modules with FSDP/DeepSpeed Stage 3, we need to quantize the parameter on the GPU
877 # and then cast it to CPU to avoid excessive memory usage on each GPU
878 # in comparison to the sharded model across GPUs.
879 if is_fsdp_enabled() or is_deepspeed_zero3_enabled():
File /usr/local/lib/python3.10/dist-packages/transformers/quantizers/quantizer_bnb_4bit.py:242, in Bnb4BitHfQuantizer.create_quantized_param(self, model, param_value, param_name, target_device, state_dict, unexpected_keys)
239 new_value = new_value.T
241 kwargs = old_value.dict
--> 242 new_value = bnb.nn.Params4bit(new_value, requires_grad=False, **kwargs).to(target_device)
244 module._parameters[tensor_name] = new_value
File /usr/local/lib/python3.10/dist-packages/bitsandbytes/nn/modules.py:331, in Params4bit.to(self, *args, **kwargs)
328 device, dtype, non_blocking, convert_to_format = torch._C._nn._parse_to(*args, **kwargs)
330 if device is not None and device.type == "cuda" and not self.bnb_quantized:
--> 331 return self._quantize(device)
332 else:
333 if self.quant_state is not None:
File /usr/local/lib/python3.10/dist-packages/bitsandbytes/nn/modules.py:296, in Params4bit._quantize(self, device)
294 def _quantize(self, device):
295 w = self.data.contiguous().to(device)
--> 296 w_4bit, quant_state = bnb.functional.quantize_4bit(
297 w,
298 blocksize=self.blocksize,
299 compress_statistics=self.compress_statistics,
300 quant_type=self.quant_type,
301 quant_storage=self.quant_storage,
302 )
303 self.data = w_4bit
304 self.quant_state = quant_state
File /usr/local/lib/python3.10/dist-packages/bitsandbytes/functional.py:1243, in quantize_4bit(A, absmax, out, blocksize, compress_statistics, quant_type, quant_storage)
1241 lib.cquantize_blockwise_fp32_nf4(*args)
1242 else:
-> 1243 raise ValueError(f"Blockwise quantization only supports 16/32-bit floats, but got {A.dtype}")
1245 code = get_4bit_type(quant_type, device=A.device)
1247 if compress_statistics:
ValueError: Blockwise quantization only supports 16/32-bit floats, but got torch.uint8
Activity
shimmyshimmer commentedon Feb 2, 2025
@DaddyCodesAlot @ichrnkv @kldzj
apologies guys it should be now fixed. We fixed the model uploads: https://huggingface.co/unsloth/Mistral-Small-24B-Instruct-2501-unsloth-bnb-4bit
Please let us know if the error still persits
ichrnkv commentedon Feb 2, 2025
Just checked, the model is loaded successfully, but I'm still getting this error during inference.
danielhanchen commentedon Feb 2, 2025
It should work now hopefully!
rolandtannous commentedon Jun 29, 2025
Hello ,
This should now be resolved with the latest version of Unsloth.
Please make sure to upgrade your installation to the latest version using
Will close this for now.
Please feel free to comment back if you are still facing the same issue after trying the above.
Thank you for using Unsloth