Repository navigation
π¨ Multimodal getters: flat get_*_embeddings under the per-item ones, removing the host sync every multimodal forward pays today
#50733
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
Changes from 5 commits
920bf22
9c00598
609d3b8
7f6d94d
77a987e
39de636
101ebe3
7a9b5fa
9d0eec9
8cb99ca
edaa6a2
cb4f81f
64ccca9
eaaf3b9
5f34687
987a483
ffa4d01
8f8c388
e651738
cb03df4
429155c
c304d77
fe1b02e
17397b9
81f62e8
33c0309
808f8f3
d2adad7
dabb4a9
a1e8e09
63bb0d9
3a71cad
28dda67
57ac726
766185c
0a0ffbf
b49b746
e95c079
c84b8de
4495b9a
558727a
937366c
8caeea1
258457b
d30c5ad
49eeadf
570c2bc
b145cd7
5994cc8
ddf6530
f560872
bad2875
e8dafbb
65bdb7a
980970f
0673b0f
5db9b16
7afabff
ff1b057
694de0a
ab20d12
75f4346
9bf7274
f929711
9c7fa43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -574,20 +574,42 @@ def __init__(self, config: Cosmos3EdgeConfig): | |
| self.visual = Cosmos3EdgeVisionModel._from_config(config.vision_config) | ||
| self.projector = Cosmos3EdgePatchMerger(config) | ||
|
|
||
| def get_image_features( | ||
| def get_image_embeddings( | ||
| self, | ||
| pixel_values: torch.Tensor, | ||
| image_grid_thw: torch.LongTensor | None = None, | ||
| **kwargs: Unpack[TransformersKwargs], | ||
| ) -> tuple | BaseModelOutputWithPooling: | ||
| r""" | ||
| All images' features as one tensor; `get_image_features` splits them per image. | ||
| """ | ||
| pixel_values = pixel_values.type(self.visual.dtype) | ||
| vision_outputs = self.visual(pixel_values, grid_thw=image_grid_thw, return_dict=True, **kwargs) | ||
| image_embeds = self.projector(vision_outputs.last_hidden_state) | ||
| vision_outputs.pooler_output = image_embeds | ||
| return vision_outputs | ||
|
|
||
| def get_image_features( | ||
| self, | ||
| pixel_values: torch.Tensor, | ||
| image_grid_thw: torch.LongTensor | None = None, | ||
| **kwargs: Unpack[TransformersKwargs], | ||
| ) -> tuple | BaseModelOutputWithPooling: | ||
| vision_outputs = self.get_image_embeddings(pixel_values, image_grid_thw, return_dict=True, **kwargs) | ||
| image_embeds = vision_outputs.pooler_output | ||
| split_sizes = (image_grid_thw.prod(-1) // self.projector.spatial_merge_size**2).tolist() | ||
| vision_outputs.pooler_output = torch.split(image_embeds, split_sizes) | ||
|
|
||
| return vision_outputs | ||
|
|
||
| def get_video_embeddings( | ||
| self, | ||
| pixel_values_videos: torch.Tensor, | ||
| video_grid_thw: torch.LongTensor | None = None, | ||
| **kwargs: Unpack[TransformersKwargs], | ||
| ) -> tuple | BaseModelOutputWithPooling: | ||
| return self.get_image_embeddings(pixel_values_videos, video_grid_thw, **kwargs) | ||
|
|
||
| def get_video_features( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TRF057 β TRF057: Why this mattersWithout it, the class and its methods ship without parameter, return and example documentation, which then has to be written by hand for each model. +@auto_docstring
@dataclass
class AcmeModelOutputWithPast(ModelOutput):
logits: torch.Tensor | None = None
+@auto_docstring
class AcmeForConditionalGeneration(AcmePreTrainedModel):
+ @auto_docstring
def forward(self, input_ids, pixel_values=None, **kwargs):
...Suppress with |
||
| self, | ||
| pixel_values_videos: torch.Tensor, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.