⚡ Optimize time embedding by precomputing static frequencies#2
Conversation
- Precompute `freqs` tensor in `generate` before the inference loop. - Update `get_time_embedding` to accept optional `freqs` parameter for backward compatibility. - Create `freqs` directly on the target device to avoid redundant transfers. - Update benchmark script with the new signature. Co-authored-by: priths7 <45918183+priths7@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
💡 What: This optimization precomputes the static frequency tensor used for time embeddings once outside the main inference loop in
sd/pipeline.py.🎯 Why: In the original implementation, the
freqstensor was recalculated, reallocated, and moved to the device in every single iteration of the sampling loop (typically 50 times per image generation). Since these frequencies only depend on constant values (10000 and 160), they are static throughout the entire inference process.📊 Measured Improvement: While environmental limitations (lack of
torchin the available environment's search path) prevented running a live benchmark, this change provides a direct efficiency boost by:arange, division,pow) from.to(device)calls within the loop.For a standard 50-step inference, this removes 49 redundant sets of computations and allocations.
PR created automatically by Jules for task 13315484921489277927 started by @priths7