Repository navigation
Conversation
…res under model CPU offload
This branch has not been deployed
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.
What does this PR do?
Fixes #15449
generate_prior_tokenscallsvision_language_encoder.get_image_features(...)directly for condition images.enable_model_cpu_offload()hooks onlyforward, so the encoder is still oncpuand image-to-image fails.This PR fires the encoder's accelerate hook before that call, as
modular_pipelines/minimax_h3/encoders.pydoes. That code has a TODO against it, and the open PR #15395 replaces it with a top-levelforwardcall, which is not possible here:GlmImageForConditionalGeneration.forwarddoes not return the condition-image tokens.Alternative: move the condition-image block after
vision_language_encoder.generate(), whoseforwardhas already moved the encoder. With transformers 5.16.1 it gives the same output (byte-identical PNG on the AMD Radeon 8060S), but I found no precedent for fixing offload by reordering. Happy to switch if preferred.#15453 makes the same change without the
hasattrcheck.Results
mainat facc812 + this diff, accelerate 1.9.0, transformers 5.16.1. Onmainthe #15449 snippet raises the device-mismatch error on both GPUs.nvidia-smi, whole GPU)max_memory_allocated)mainon GPU* test components with vision
patch_size16 /image_size64 to match the processor. Unchanged vsmain(diff 0.0): text-to-image on GPU and with model offload, image-to-image on GPU. The model card text-to-image example with model offload gives a PNG byte-identical tomain(130.1 s, peak 20344 MiB), andpytest tests/pipelines/glm_imagegives 35 passed, 2 skipped onmainand on this branch (NVIDIA GeForce RTX 5090).Outside the reported case:
prior_token_idsgiven, or without an accelerate hook on the encoder (group offloading uses other hooks).pre_forward(module)call per image-to-image call: no output change fordevice_map="balanced"/force_hooks=True; nothing moves if the encoder is already on the device. Not measured: a customModelHookwhosepre_forwardneeds inputs (would raise),cpu_offload_with_hookon the encoder only (a device mismatch if the execution device iscpu), anothermodel_cpu_offload_seq, multi-device maps, several condition images, batch > 1.Self-review notes (
self-reviewskill): blocking none.hasattr(hook, "pre_forward")is always true, kept to matchapply_forward_hook. No test:MemoryTesterMixinuses text-to-image inputs and the test's tiny components cannot run image-to-image (visionpatch_size8, processor 16).ruffcheck / format pass.Before submitting
self-reviewskill on the diff?enable_model_cpu_offload()(device mismatch inget_image_features) #15449documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Draft; reviewers will be tagged when it is ready.