Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AssertionError in clip conversion script #30321

Merged
merged 4 commits into from
Apr 18, 2024
Merged

Fix AssertionError in clip conversion script #30321

merged 4 commits into from
Apr 18, 2024

Conversation

ydshieh
Copy link
Collaborator

@ydshieh ydshieh commented Apr 18, 2024

What does this PR do?

Fix #30037(AssertionError) part. The failure comes from the fact that the prepared inputs in not really meaningful (not processed by clip tokenizer).

The conversion is still failing with saftensors error

ValueError: You are trying to save a non contiguous tensor

I will ping people once this PR merged.

Full log

Traceback (most recent call last):
  File "convert_clip_original_pytorch_to_hf.py", line 146, in <module>
    convert_clip_checkpoint(args.checkpoint_path, args.pytorch_dump_folder_path, args.config_path)
  File "/usr/local/lib/python3.8/dist-packages/torch/utils/_contextlib.py", line 115, in decorate_context
    return func(*args, **kwargs)
  File "convert_clip_original_pytorch_to_hf.py", line 136, in convert_clip_checkpoint
    hf_model.save_pretrained(pytorch_dump_folder_path)
  File "/transformers/src/transformers/modeling_utils.py", line 2584, in save_pretrained
    safe_save_file(shard, os.path.join(save_directory, shard_file), metadata={"format": "pt"})
  File "/usr/local/lib/python3.8/dist-packages/safetensors/torch.py", line 284, in save_file
    serialize_file(_flatten(tensors), filename, metadata=metadata)
  File "/usr/local/lib/python3.8/dist-packages/safetensors/torch.py", line 488, in _flatten
    return {
  File "/usr/local/lib/python3.8/dist-packages/safetensors/torch.py", line 492, in <dictcomp>
    "data": _tobytes(v, k),
  File "/usr/local/lib/python3.8/dist-packages/safetensors/torch.py", line 406, in _tobytes
    raise ValueError(
ValueError: You are trying to save a non contiguous tensor: `visual_projection.weight` which is not allowed. It either means you are trying to save tensors which are reference of each other in which case it's recommended to save only the full tensors, and reslice at load time, or simply call `.contiguous()` on your tensor to pack it before saving.

@ydshieh ydshieh changed the title fix Fix AssertionError in clip conversion script Apr 18, 2024
@ydshieh ydshieh requested a review from amyeroberts April 18, 2024 14:19
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Copy link
Collaborator

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome - thanks for digging into this and fixing!

@ydshieh ydshieh merged commit d9850ab into main Apr 18, 2024
8 checks passed
@ydshieh ydshieh deleted the fix_clip branch April 18, 2024 18:18
ydshieh added a commit that referenced this pull request Apr 23, 2024
* fix

* fix

* fix

* update comments

---------

Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AssertionError when converting openai clip's weight to hf with higher transformers version
3 participants