Skip to content

Cant load model with transformers. #111

Closed

Description

@bibidentuhanoi

Notebook: https://colab.research.google.com/drive/1Dyauq4kTZoLewQ1cApceUQVNcnnNTzg_?usp=sharing
After using the option:  if True: model.save_pretrained_merged("x", tokenizer, save_method = "merged_16bit",) to save the model to the Colab local disk, i have tried to use it with the code below.

model = AutoModelForCausalLM.from_pretrained( "/content/x", load_in_8bit=True, device_map={"": 0}, )

and I received this error:

UnpicklingError: Weights only load failed. Re-running torch.loadwithweights_onlyset toFalse will likely succeed, but it can result in arbitrary code execution.Do it only if you get the file from a trusted source. WeightsUnpickler error: Unsupported operand 149 During handling of the above exception, another exception occurred: UnicodeDecodeError Traceback (most recent call last) UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 128: invalid start byte During handling of the above exception, another exception occurred: OSError Traceback (most recent call last) [/usr/local/lib/python3.10/dist-packages/transformers/modeling_utils.py](https://localhost:8080/#) in load_state_dict(checkpoint_file) 552 ) from e 553 except (UnicodeDecodeError, ValueError): --> 554 raise OSError( 555 f"Unable to load weights from pytorch checkpoint file for '{checkpoint_file}' " 556 f"at '{checkpoint_file}'. " OSError: Unable to load weights from pytorch checkpoint file for '/content/x/pytorch_model-00001-of-00003.bin' at '/content/x/pytorch_model-00001-of-00003.bin'. If you tried to load a PyTorch model from a TF 2.0 checkpoint, please set from_tf=True.

I also tried to add  from_tf=True,
After that, I got: ValueError: Converting into 4-bit or 8-bit weights from tf/flax weights is currently not supported, please make sure the weights are in PyTorch format.

Activity

  1. danielhanchen commented on Jan 20, 2024

    @danielhanchen
    Member

    @bibidentuhanoi Sorry on the delay! Oh yep someone brought this up - its should be fixed now! But on ur model specifically - if you go to config.json, edit it, and delete the entirety of

      "quantization_config": {
        "bnb_4bit_compute_dtype": "float16",
        "bnb_4bit_quant_type": "nf4",
        "bnb_4bit_use_double_quant": true,
        "llm_int8_enable_fp32_cpu_offload": false,
        "llm_int8_has_fp16_weight": false,
        "llm_int8_skip_modules": "null",
        "llm_int8_threshold": 6.0,
        "load_in_4bit": true,
        "load_in_8bit": false,
        "quant_method": "bitsandbytes"
      },
    

    then save it.

    It should function!

  2. bibidentuhanoi commented on Jan 20, 2024

    @bibidentuhanoi
    Author

    I have checked the model config but there is no quantization_config:

    {
      "_name_or_path": "unsloth/mistral-7b",
      "architectures": [
        "MistralForCausalLM"
      ],
      "attention_dropout": 0.0,
      "bos_token_id": 1,
      "eos_token_id": 2,
      "hidden_act": "silu",
      "hidden_size": 4096,
      "initializer_range": 0.02,
      "intermediate_size": 14336,
      "max_position_embeddings": 32768,
      "model_type": "mistral",
      "num_attention_heads": 32,
      "num_hidden_layers": 32,
      "num_key_value_heads": 8,
      "pad_token_id": 2,
      "rms_norm_eps": 1e-05,
      "rope_theta": 10000.0,
      "sliding_window": 4096,
      "tie_word_embeddings": false,
      "torch_dtype": "float16",
      "transformers_version": "4.38.0.dev0",
      "unsloth_version": "2024.1",
      "use_cache": true,
      "vocab_size": 32000
    }
    

    The problem is still there.
    I have tried this 10-minute commit from your last commit.

  3. danielhanchen commented on Jan 21, 2024

    @danielhanchen
    Member

    @bibidentuhanoi Oops you're actually correct - I'll push a fix today! Sorry again! Thanks for the report as well!

  4. danielhanchen commented on Jan 21, 2024

    @danielhanchen
    Member

    @bibidentuhanoi Fixed it!! Sorry you might have to reinstall Unsloth - again sorry on the issue! pip install --upgrade --force-reinstall --no-cache-dir git+https://github.com/unslothai/unsloth.git (no dependencies will get updated)

    I confirmed it was my fault, as HF does not like pickle.HIGHEST_PROTOCOL

  5. bibidentuhanoi commented on Jan 21, 2024

    @bibidentuhanoi
    Author

    Everything's running smoothly on my end! Thank you for the quick fix. This project is absolutely amazing and has been a real time-saver for me.
    Thank you.

  6. danielhanchen commented on Jan 21, 2024

    @danielhanchen
    Member

    @bibidentuhanoi Thanks for the kind words!! :))

  7. added a commit that references this issue on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions