Fix #18: Strict runtime integrity guards for model loading - #22
Open
Dikshant-Neupane wants to merge 1 commit into
Open
Fix #18: Strict runtime integrity guards for model loading#22Dikshant-Neupane wants to merge 1 commit into
Dikshant-Neupane wants to merge 1 commit into
Conversation
Author
|
@microsoft-github-policy-service agree |
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.
Description
This PR addresses Issue #18 by fixing silent failure states during model loading, parameter shape expansion, and context management. It introduces strict runtime guards to ensure that architectural mismatches and missing critical weights loudly fail rather than running silently with garbage initialization.
Key Changes
Strict Checkpoint Validation (
mage_flow.py,pipeline.py,utils.py)CRITICAL_LAYERSdefinition (img_in,txt_in,proj_out,final_layer.linear).validate_state_dict_keysto wrapload_state_dict. Checkpoint loading now throws an explicitKeyErrorwith a diagnostic message if a critical layer is missing.Safe Shape Expansion Guards (
utils.py)optionally_expand_state_dict(). If a shape mismatch occurs on a critical projection layer, it now throws aValueErrorinstead of silently zero-padding (which would produce dead feature channels).logger.warning.Robust Context Manager Cleanup (
mage_text.py)except Exception: passanti-pattern in_full_output_mode.try...exceptwrapper that logs the exact failure vialoguruand re-raises the exception to prevent the model from getting stuck in an invalid output mode.VAE-Transformer Mismatch Assertion (
pipeline.py)latent_channelsagainst the Transformerin_channels.ValueErrorif the user accidentally pairs mismatched architectures (e.g., a 16-channel VAE with an 8-channel Transformer).Unit Tests Added
tests/test_integrity_guards.pyproviding a lightweightpytestsuite to verify that these specific exceptions trigger reliably without false positives.Related Issues