Conversation
|
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. |
Member
|
Thanks for reporting! Do you mean the generation in |
Member
Author
|
Repro (transformers @ import torch
from transformers import AutoProcessor, SmolVLMForConditionalGeneration
model_id = "HuggingFaceTB/SmolVLM2-500M-Video-Instruct"
video_path="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/blog/assisted-generation/gif_1_1080p.mov"
dtype = torch.bfloat16
processor = AutoProcessor.from_pretrained(model_id)
model = SmolVLMForConditionalGeneration.from_pretrained(
model_id,
torch_dtype=dtype,
device_map="cuda:0",
)
messages = [
{
"role": "user",
"content": [
{"type": "video", "path": video_path},
{"type": "text", "text": "Describe this video in detail"}
]
},
]
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(device=model.device, dtype=dtype)
generated_ids = model.generate(**inputs, do_sample=False, max_new_tokens=100)
generated_texts = processor.batch_decode(generated_ids, skip_special_tokens=False)
print(generated_texts[0])Output: Notes:
transformers @ transformers @ (truncated there) transformers @ (Same as |
Member
Author
|
Closing, superseded by #39147. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
There's a bug in smolvlm2 video processing (but keep reading, there's more): the list of frames that make up the prompt is malformed. While debugging transformers
v4.52.4, this appeared to be because thereturn_row_col_infowas removed from the kwargs, possibly in #38105.However, this fix only works if we apply it on top of
v4.52.4, but not onmain. Onmain, the chat template goes through a new path and generation is wrong (before or after the fix). In addition,mainseems to decode all the frames in the video at full resolution, I got a tensor with shape(559, 730, 1920, 3)here. This is not the case inv4.52.4(I get 9 frames for the same video, already downscaled).cc @zucchini-nlp, happy to take a deeper look if you have any hints on how to proceed.
Reported in Blaizzy/mlx-vlm#388
Processing works in #37291, but it looks out of date with
main.