Fix/issue 19 - #23
Open
Dikshant-Neupane wants to merge 2 commits into
Open
Conversation
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 #19, refactoring the
Mage-VAElatent tokenizer (mage_vae.pyandutils.py) to eliminate spatial artifacts, prevent precision quantization noise, and enforce deterministic local RNG.Key Changes
Reflection Padding Guard (
utils.py,mage_vae.py)pad_to_patch_multiplehelper that applies dynamic spatial reflection padding to ensure input images are exact multiples of 16.math.ceildivision with safe integer division//.FP32 Precision Guard for Posterior Sampling (
mage_vae.py)meanandlogvartotorch.float32insideencode()prior to computingtorch.exp(0.5 * logvar).bfloat16.Dynamic adaLN Cache Management (
mage_vae.py)_ConstAdaLNto retain a reference to theoriginal_mlpalongside the constant-folded buffer.t; if a non-zero timestep is detected (t > 1e-5), the_ConstAdaLNmodules gracefully bypass the cached buffer and execute the live MLP, properly supporting multi-step progressive decoding paths.set_adaln_cache()method toMageVAEfor explicit cache state control.Deterministic Local RNG (
mage_vae.py)encode()signature to accept an explicitgenerator: torch.Generator | None = None.torch.randn_likewithtorch.randn(..., generator=generator). This decouples the sampling process from PyTorch's volatile global RNG state, guaranteeing deterministic latents across runs.Test Suite (
tests/test_vae_integrity.py)Related Issues