fix: convert boundary_ratio from timestep space to index space#32
Open
Auraithm wants to merge 2 commits intoOpenMOSS:mainfrom
Open
fix: convert boundary_ratio from timestep space to index space#32Auraithm wants to merge 2 commits intoOpenMOSS:mainfrom
Auraithm wants to merge 2 commits intoOpenMOSS:mainfrom
Conversation
…verse sigma_shift
Collaborator
|
上下文:这里的 boundary 应该是 sigma_shift 前的 index 边界 因此不要硬编码:switch_dit_boundary: float = 0.358, #FIXME(dhyu): |
Collaborator
|
@Auraithm 最好贴个测试通过的例子 |
…ft formula Replace the analytical inverse sigma_shift formula with a direct table lookup on scheduler.timesteps. This avoids floating-point precision issues (e.g. 0.24999 vs 0.25) and the sigma_min != 0 approximation error, giving an exact boundary at the intended timestep threshold.
Author
|
测试命令 cd xxx/MOVA && python -c "
import torch
from mova.diffusion.schedulers.flow_match import FlowMatchScheduler
from mova.diffusion.pipelines.mova_train import TimestepConfig, compute_density_for_timestep_sampling
scheduler = FlowMatchScheduler(num_train_timesteps=1000, shift=3.0)
scheduler.set_timesteps(1000, training=True)
boundary_ratio = 0.9
boundary = (scheduler.timesteps >= boundary_ratio * scheduler.num_train_timesteps).sum().item() / scheduler.num_train_timesteps
boundary_idx = int(boundary * 1000)
print(f'boundary = {boundary}, boundary_idx = {boundary_idx}')
print(f'timesteps[{boundary_idx-1}] = {scheduler.timesteps[boundary_idx-1].item():.2f}')
print(f'timesteps[{boundary_idx}] = {scheduler.timesteps[boundary_idx].item():.2f}')
print()
print('--- 偶数步 (DiT1) 采样 100 次 ---')
min_ts, max_ts = float('inf'), float('-inf')
for _ in range(100):
u = compute_density_for_timestep_sampling('uniform', 1, min_timestep_boundary=0.0, max_timestep_boundary=boundary)
tid = torch.clamp(torch.floor(u * 1000).long(), 0, boundary_idx - 1).item()
ts = scheduler.timesteps[tid].item()
min_ts, max_ts = min(min_ts, ts), max(max_ts, ts)
assert min_ts >= 900
print(f'[PASS] [{min_ts:.2f}, {max_ts:.2f}], 全部 >= 900')
print()
print('--- 奇数步 (DiT2) 采样 100 次 ---')
min_ts, max_ts = float('inf'), float('-inf')
for _ in range(100):
u = compute_density_for_timestep_sampling('uniform', 1, min_timestep_boundary=boundary, max_timestep_boundary=1.0)
tid = torch.clamp(torch.floor(u * 1000).long(), boundary_idx, 999).item()
ts = scheduler.timesteps[tid].item()
min_ts, max_ts = min(min_ts, ts), max(max_ts, ts)
assert max_ts < 900
print(f'[PASS] [{min_ts:.2f}, {max_ts:.2f}], 全部 < 900')
print()
print('ALL CHECKS PASSED')
"结果: |
yhzx233
approved these changes
Feb 15, 2026
Collaborator
yhzx233
left a comment
There was a problem hiding this comment.
也许这个boundary可以提前算好存为成员变量
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.
Summary
boundary_ratio=0.9represents the DiT1/DiT2 switch point at timestep 900. In inference, this value is correctly compared against actual timestep values. However, intraining_step, it was incorrectly used as an index fraction formax/min_timestep_boundary.Due to sigma_shift (flow_match.py L57), the scheduler's timestep array is non-linearly spaced — timestep 900 sits at index ~250 (shift=3), not index 900. Using 0.9 as the index boundary caused DiT1 to be trained on 90% of indices and DiT2 on only 10%, while in inference DiT2 handles the majority of denoising (timestep 900→0).
Fix
Apply inverse sigma_shift to convert
boundary_ratiofrom timestep space to index space before passing it tomax/min_timestep_boundary. This aligns training with inference behavior.Reference