Questions on 1-Step Finetuning and Deterministic Inference
First off, fantastic work on "DiffusionShader"! The quality and ingenuity of the paper are truly inspiring, and it's been a great resource for my own research.
I'm currently looking into the deterministic approach for the inverse rendering task and have a couple of questions regarding the implementation details. I would be very grateful for any insights the authors could provide.
1. 1-Step Finetuning Strategy
I am trying to fully understand the training setup for the geometry prediction network.
My current understanding is that for the 1-step finetuning, you provide a zero tensor as the initial noisy latent and condition the model on the maximum noise level. Following the Karras noise schedule (as adopted from SVD), this would correspond to sigma ≈ 700.
Could you please confirm if this assumption about the training setup is correct?
2. Deterministic Inference Implementation
My second question relates to the latent update rule during deterministic inference. I was particularly intrigued by this specific block of code:
if self.use_deterministic_mode:
latents = -noise_pred
else:
# compute the previous noisy sample x_t -> x_t-1
latents = self.scheduler.step(noise_pred, t, latents).prev_sample
I am still learning these techniques and would love to understand the intuition behind this implementation. Why is directly assigning the latent to -noise_pred a more suitable approach for a deterministic prediction task compared to a standard single-step denoising call using scheduler.step(...)? What is the theoretical motivation for this direct assignment?
Thank you for your time and for sharing this incredible work with the community!
I think what you proposed also makes sense! :)
The deterministic finetuning follows the observations from two concurrent works: https://gonzalomartingarcia.github.io/diffusion-e2e-ft/ https://lotus3d.github.io/
It was a very quick implementation out of curiosity, and my hunch at that time was to avoid potential numerical/precision issues caused by large sigmas, which shrinks the scale of latents.
Here’s the training code related to losses:
# Predict the noise residual and compute loss
model_pred = unet(
inp_noisy_latents, timesteps, encoder_hidden_states,
added_time_ids=added_time_ids, input_context=input_context, time_context=time_context
).sample
if not cfg.use_deterministic_mode:
# Denoise the latents
c_out = -sigmas / ((sigmas**2 + 1)**0.5)
c_skip = 1 / (sigmas**2 + 1)
denoised_latents = model_pred * c_out + c_skip * noisy_latents
weighing = (1 + sigmas ** 2) * (sigmas**-2.0)
# MSE loss
loss = torch.mean(
(weighing.float() * (denoised_latents.float() -
target.float()) ** 2).reshape(target.shape[0], -1),
dim=1,
)
else:
denoised_latents = -model_pred
# MSE loss
loss = torch.mean(
((denoised_latents.float() - target.float()) ** 2).reshape(target.shape[0], -1),
dim=1,
)
Unfortunately we did not release the deterministic fine-tuned weights at the moment, so this flag use_deterministic_mode is not deemed functioning.
For faster inference, can simply try with fewer steps, which we found often working in a reasonable manner.
Thank you so much for providing the helpful code snippet regarding the training loss calculation!
After studying the snippet, I have a couple of clarifying questions about the methodology, if you have a moment.
1. Regarding the deterministic_mode
My first question is about the logic in the deterministic_mode. I noticed that in your main training branch (if not cfg.use_deterministic_mode), as sigma approaches infinity (σ -> ∞), the preconditioning factors simplify as follows:
c_skip = 1 / (σ² + 1)approaches 0.c_out = -σ / sqrt(σ² + 1)approaches -1.
This simplifies the denoising equation denoised_latents = model_pred * c_out + c_skip * noisy_latents to become denoised_latents ≈ -model_pred.
Is my understanding correct?
2. Regarding the UNet Preconditioning in the EDM Framework:
My second question is regarding the network preconditioning, as my own work also involves fine-tuning SVD, which similarly adopts the Karras/EDM sigma schedule for its continuous time representation.
My understanding of the EDM framework is that two preconditioning steps are critical for ensuring numerical stability across the full range of sigma:
-
First, the input scaling factor:
c_in = 1 / sqrt(sigma**2 + 1)This coefficient is used to scale the input
noisy_latents. Its purpose is to normalize the input's variance to 1 across all noise levels, which is a critical step for ensuring the network's numerical stability. -
Second, the noise-level embedding:
c_noise = log(sigma) / 4This value, derived from the continuous
sigma, is passed to the UNet as its time conditioning. It provides the model with precise information about the current noise level, which is more effective in the continuous EDM framework than discrete integer timesteps.
When looking at your provided UNet call, unet(inp_noisy_latents, timesteps, ...), it appears that the inp_noisy_latents are passed directly without the c_in scaling, and that the model is conditioned on integer timesteps rather than a c_noise-style embedding derived from sigma.
I would be very grateful if you could clarify this implementation detail. I was wondering if this was a deliberate design choice you found beneficial for your task, or perhaps if these crucial preconditioning steps are handled elsewhere in your pipeline and were not shown in this particular snippet?
I believe I now fully understand your implementation — everything makes sense. If I’m not mistaken, you are likely following this reference as the basis for your SVD finetuning:
https://github.com/pixeli99/SVD_Xtend/blob/609fbf92a3e39a78ed1e2a9e0764a1e912103c48/train_svd.py#L969
In this implementation, the handling of c_in and c_noise is already included in inp_noisy_latents and timesteps, and the loss calculation (with denoised_latents ≈ -model_pred) corresponds to the approximation at sigma = max_sigma(700.0 in the svd).
So I believe I’ve now got a good understanding of how it works — thanks a lot!
I just have one quick question for confirmation:
When training with deterministic_mode, is noisy_latent also set as a zero tensor, just like in your inference code?
And at the same time, is sigma also fixed to a constant value (e.g., 700.0 as in SVD)?
denoised_latents = -model_pred is a simplified version as sigma approaches inf.
When training with deterministic_mode, is noisy_latent also set as a zero tensor, just like in your inference code?
That's correct. inp_noisy_latents = torch.zeros_like(latents)
And at the same time, is sigma also fixed to a constant value (e.g., 700.0 as in SVD)?
Yes it's using a fixed value.
noise_scheduler = EulerDiscreteScheduler.from_pretrained(cfg.pretrained_model_name_or_path,
subfolder="scheduler", timestep_spacing="trailing")
noise_scheduler.set_timesteps(1, device=accelerator.device)
deterministic_timestep = noise_scheduler.timesteps
Thank you so much for the detailed explanation! I have a much clearer understanding now, and it seems my implementation is basically aligned with your approach.
I have one follow-up question regarding the performance. In your experience, how is the quality of the results from this deterministically trained model?
I'm asking because in my own task, I've noticed this method can sometimes produce rather blurry outputs. My hypothesis is that the model might be learning to output an "average" of all possible results in this condition, thus losing some high-frequency details.
Would love to hear your insights on this. Thanks again!
Our observation is the results can get blurry on regions with high-uncertainty, such as foliage, and might flatten out fine structures on surfaces. The perceptual metrics such as LPIPS drop, but error metrics PSNR, MSE improves. This is the case for both inverse renderer and forward renderer.
Visually pleasant and detailed result is critical to this work, so we decide to not use deterministic version.
We had a paragraph in Sec 5.3 of paper:
One-step deterministic fine-tuning. We also ablate the design choice of 1-step deterministic fine-tuning in Table 3 and 4. By default, the inverse renderer performs 20 denois- ing steps during inference. Building on recent findings in image diffusion models [47], we demonstrate that strongly conditioned video diffusion models can also be fine-tuned as 1-step deterministic models. Despite the significantly reduced computational cost, we observe that 1-step models consistently produce more “accurate” predictions and outper- form multi-step stochastic models in photometric evaluations such as PSNR scores. However, the 1-step model enforces deterministic output, which can result in blurrier predictions for ambiguous regions with high-frequency details, thus yielding lower perceptual metrics, such as LPIPS. For neural forward rendering and relighting tasks, we use multi-step stochastic models to capture more realistic details, though we note that 1-step models can be a competitive choice for error-sensitive tasks and enhancing runtime efficiency.
Thank you! That aligns perfectly with our experiments:)