-
Notifications
You must be signed in to change notification settings - Fork 210
Fix multimodal hidden-state preparation for Qwen3-VL models #526
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
Open
liusy58
wants to merge
2
commits into
sgl-project:main
Choose a base branch
from
liusy58:fix_prepare_hidden_states
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -72,6 +72,8 @@ class DataPoint: | |||||||||
| loss_mask: torch.Tensor | ||||||||||
| hidden_state: torch.Tensor | ||||||||||
| aux_hidden_state: Optional[torch.Tensor] = None | ||||||||||
| pixel_values: Optional[torch.Tensor] = None | ||||||||||
| image_grid_thw: Optional[torch.Tensor] = None | ||||||||||
|
|
||||||||||
|
|
||||||||||
| def parse_args(): | ||||||||||
|
|
@@ -187,14 +189,19 @@ def build_target_model( | |||||||||
| ) | ||||||||||
| else: | ||||||||||
| target_model_kwargs = SGLangBackendArgs.from_args(args).to_kwargs() | ||||||||||
| if hasattr(model_config, "dtype") and model_config.dtype is not None: | ||||||||||
| torch_dtype = model_config.dtype | ||||||||||
| elif hasattr(model_config, "text_config") and hasattr( | ||||||||||
| model_config.text_config, "dtype" | ||||||||||
| ): | ||||||||||
| torch_dtype = model_config.text_config.dtype | ||||||||||
| else: | ||||||||||
| torch_dtype = getattr(model_config, "torch_dtype", "bfloat16") | ||||||||||
|
|
||||||||||
| target_model = get_eagle3_target_model( | ||||||||||
| pretrained_model_name_or_path=args.target_model_path, | ||||||||||
| backend="sglang", # we set this as the default backend to minimize precision mismatch in training and serving | ||||||||||
| torch_dtype=( | ||||||||||
| model_config.dtype | ||||||||||
| if hasattr(model_config, "dtype") | ||||||||||
| else model_config.torch_dtype | ||||||||||
| ), | ||||||||||
| torch_dtype=torch_dtype, | ||||||||||
| device="cuda", | ||||||||||
| cache_dir=args.model_download_dir, | ||||||||||
| trust_remote_code=args.trust_remote_code, | ||||||||||
|
|
@@ -488,6 +495,8 @@ def generate( | |||||||||
| "attention_mask": batch["attention_mask"][valid_indices_in_batch], | ||||||||||
| "loss_mask": batch["loss_mask"][valid_indices_in_batch], | ||||||||||
| } | ||||||||||
| pixel_values = batch["pixel_values"][valid_indices_in_batch] | ||||||||||
| image_grid_thw = batch["image_grid_thw"][valid_indices_in_batch] | ||||||||||
| del batch | ||||||||||
| if num_valid == 0: | ||||||||||
| # Data has already been generated, no sample processing, update progress bar. | ||||||||||
|
|
@@ -542,6 +551,8 @@ def generate( | |||||||||
| data_point = DataPoint( | ||||||||||
| input_ids=filtered_batch["input_ids"][i].clone(), | ||||||||||
| loss_mask=filtered_batch["loss_mask"][i].clone(), | ||||||||||
| pixel_values=pixel_values[i].clone(), | ||||||||||
| image_grid_thw=image_grid_thw[i].clone(), | ||||||||||
|
Comment on lines
+554
to
+555
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. Accessing
Suggested change
|
||||||||||
| hidden_state=last_hidden_states, | ||||||||||
| aux_hidden_state=aux_hidden_states, | ||||||||||
| ) | ||||||||||
|
|
||||||||||
Oops, something went wrong.
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 was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for determining
torch_dtypecan be simplified and made more robust by usinggetattrwith defaults and explicitly checking forNonevalues in nested configurations.