[Core] Simplify multimodal masking (#34246)
Signed-off-by: Lukas Geiger <lukas.geiger94@gmail.com>
This commit is contained in:
@@ -468,14 +468,8 @@ def _merge_multimodal_embeddings(
|
||||
input_dtype = inputs_embeds.dtype
|
||||
|
||||
try:
|
||||
# For debugging
|
||||
# inputs_embeds[is_multimodal] = mm_embeds_flat.to(dtype=input_dtype)
|
||||
|
||||
# NOTE: This can avoid D2H sync (#22105), but fails to
|
||||
# raise an error if is_multimodal.sum() < len(mm_embeds_flat)
|
||||
inputs_embeds.masked_scatter_(
|
||||
is_multimodal.unsqueeze(-1), mm_embeds_flat.to(dtype=input_dtype)
|
||||
)
|
||||
# If is_multimodal is on CPU this avoids a D2H sync
|
||||
inputs_embeds[is_multimodal] = mm_embeds_flat.to(dtype=input_dtype)
|
||||
except RuntimeError as e:
|
||||
num_actual_tokens = len(mm_embeds_flat)
|
||||
num_expected_tokens = is_multimodal.sum().item()
|
||||
@@ -488,7 +482,7 @@ def _merge_multimodal_embeddings(
|
||||
f"multimodal tokens to {num_expected_tokens} placeholders"
|
||||
) from e
|
||||
|
||||
raise ValueError("Error during masked scatter operation") from e
|
||||
raise ValueError("Error during index put operation") from e
|
||||
|
||||
return inputs_embeds
|
||||
|
||||
|
||||
Reference in New Issue
Block a user