Repository navigation
Expand file tree
/
Copy path0001-streamedit-code-fixes.patch
More file actions
452 lines (422 loc) · 21.9 KB
/
Copy path0001-streamedit-code-fixes.patch
File metadata and controls
452 lines (422 loc) · 21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
diff --git a/LongLive_StreamEdit/inference_edit_streamedit.py b/LongLive_StreamEdit/inference_edit_streamedit.py
index a788d20..b4a9e1f 100644
--- a/LongLive_StreamEdit/inference_edit_streamedit.py
+++ b/LongLive_StreamEdit/inference_edit_streamedit.py
@@ -41,6 +41,8 @@ def load_pipe(args):
config = OmegaConf.load(args.config_path)
config['model_kwargs']['timestep_shift'] = args.flow_shift
config['denoising_step_list'] = np.arange(1000, 0, -1000 / args.step).astype(int).tolist()
+ config['noise_alpha_fg'] = args.noise_alpha_fg
+ config['dump_masks_dir'] = args.dump_masks_dir
# infinity relative rope
config['model_kwargs']['use_infinite_attention'] = getattr(args, 'use_infinite_attention', False)
@@ -162,6 +164,12 @@ if __name__ == '__main__':
# hyper-parameters
parser.add_argument("--fg_boost_factor", type=float, default=2.0, help='CrossAttn Boosting')
parser.add_argument("--blend_power", type=float, default=2.0, help='rho')
+ parser.add_argument("--dump_masks_dir", type=str, default=None,
+ help='write per-chunk cross-attention masks here (PNG)')
+ parser.add_argument("--noise_alpha_fg", type=float, default=None,
+ help='temporal-noise correlation inside editing regions; '
+ 'None (default) keeps the original uniform correlation, '
+ '0 fully decorrelates the foreground across chunks')
# model settings
parser.add_argument("--step", type=int, default=15, help='1~1000')
diff --git a/LongLive_StreamEdit/pipeline/edit_causal_inference.py b/LongLive_StreamEdit/pipeline/edit_causal_inference.py
index 5a536af..3ce63d8 100644
--- a/LongLive_StreamEdit/pipeline/edit_causal_inference.py
+++ b/LongLive_StreamEdit/pipeline/edit_causal_inference.py
@@ -45,6 +45,11 @@ class EditCausalInferencePipeline(torch.nn.Module):
self.kv_cache1 = None
self.args = args
+ # ✨ optional lower temporal-noise correlation inside editing regions;
+ # None keeps the original uniform correlation
+ self.noise_alpha_fg = getattr(args, "noise_alpha_fg", None)
+ # ✨ optional directory for per-chunk mask dumps (looking, not measuring)
+ self.dump_masks_dir = getattr(args, "dump_masks_dir", None)
self.num_frame_per_block = getattr(args, "num_frame_per_block", 1)
self.local_attn_size = args.model_kwargs.local_attn_size
@@ -264,10 +269,12 @@ class EditCausalInferencePipeline(torch.nn.Module):
# Step 3: Temporal denoising loop
denoising_step_list = self.denoising_step_list
+ _dump_chunk_idx = -1
all_num_frames = [self.num_frame_per_block] * num_blocks
if independent_first_frame and trg_initial_latent is None:
all_num_frames = [1] + all_num_frames
for current_num_frames in tqdm(all_num_frames):
+ _dump_chunk_idx += 1
if profile:
block_start.record()
@@ -283,7 +290,11 @@ class EditCausalInferencePipeline(torch.nn.Module):
# obtain currently inprocessed kv_cache for dual branch
shared_dict_dual = dict()
+ self._kv_cache_to(kv_cache_trg, 'cuda', low_memory)
kv_cache_dual = self._concat_kv_cache(kv_cache_src, kv_cache_trg, shared_dict=shared_dict_dual)
+ # the dual cache now holds a copy of the target cache, so the target cache
+ # can be offloaded for the whole spatial denoising loop (the memory peak)
+ self._kv_cache_to(kv_cache_trg, 'cpu', low_memory)
#✨ forward clean source video to get source mask, and store into kv_cache
self._register_crossattn_mask_gatherer(crossattn_cache_src, tok_src, layers=mask_layers, fg_scale=fg_scale)
@@ -378,6 +389,8 @@ class EditCausalInferencePipeline(torch.nn.Module):
crossattn_cache_dual, size=(current_num_frames, height, width), scale_factor=16
)
inloop_trg_fg_mask_bin = inloop_src_trg_fg_mask_bin.chunk(2, dim=0)[1]
+ self._dump_masks(_dump_chunk_idx, src_map=src_fg_mask_map,
+ vis_bin=mask_bin_vis, vis_soft=mask_soft_vis)
# inject union of origin src and in-processing trg masks to kv_cache
inloop_trg_fg_mask = inloop_trg_fg_mask_bin | src_fg_mask_bin
self._inject_masks_to_kv_cache(
@@ -494,6 +507,42 @@ class EditCausalInferencePipeline(torch.nn.Module):
pass
+ def _dump_masks(self, chunk_idx, src_map=None, vis_bin=None, vis_soft=None):
+ '''
+ ✨ Write the masks this chunk actually used to self.dump_masks_dir.
+ Nothing here is recomputed: mask_soft_vis / mask_bin_vis are already
+ produced (at full 480x832) by _aggregate_crossattn_mask and were
+ previously discarded. Row order in vis_* is [src, trg].
+ '''
+ d = getattr(self, "dump_masks_dir", None)
+ if not d:
+ return
+ import numpy as np
+ from PIL import Image
+ os.makedirs(d, exist_ok=True)
+
+ def save(arr, name):
+ a = arr.detach().float().cpu().numpy()
+ a = (a - a.min()) / (a.max() - a.min() + 1e-8) if a.max() > a.min() else a * 0
+ for f in range(a.shape[0]):
+ Image.fromarray((a[f] * 255).astype("uint8")).save(
+ os.path.join(d, "c%03d_f%d_%s.png" % (chunk_idx, f, name)))
+
+ if src_map is not None: # M^src, the reliable floor
+ m = src_map[0]
+ if m.shape[-1] < 400: # latent res -> video res
+ m = F.interpolate(m.float().unsqueeze(0), scale_factor=16,
+ mode="nearest").squeeze(0) > 0.5
+ save(m, "Msrc")
+ if vis_bin is not None: # [2B, F, H, W] = [src, trg]
+ save(vis_bin[0], "bin_src")
+ if vis_bin.shape[0] > 1:
+ save(vis_bin[1], "bin_trg")
+ if vis_soft is not None:
+ save(vis_soft[0], "soft_src")
+ if vis_soft.shape[0] > 1:
+ save(vis_soft[1], "soft_trg")
+
def _initialize_kv_cache(self, batch_size, dtype, device, kv_cache_size_override: int | None = None):
"""
Initialize a Per-GPU KV cache for the Wan model.
@@ -620,24 +669,14 @@ class EditCausalInferencePipeline(torch.nn.Module):
index_kvc = kvc_1
for b_idx in range(self.num_transformer_blocks):
kv_cache1.append({
- "k": torch.cat((kvc_1[b_idx]["k"], kvc_2[b_idx]["k"]), dim=0).clone(),
- "v": torch.cat((kvc_1[b_idx]["v"], kvc_2[b_idx]["v"]), dim=0).clone(),
+ "k": torch.cat((kvc_1[b_idx]["k"], kvc_2[b_idx]["k"]), dim=0),
+ "v": torch.cat((kvc_1[b_idx]["v"], kvc_2[b_idx]["v"]), dim=0),
"global_end_index": index_kvc[b_idx]["global_end_index"].clone(),
"local_end_index": index_kvc[b_idx]["local_end_index"].clone(),
"shared_dict": shared_dict,
})
return kv_cache1
- def _append_clean_src_kv_cache(self, kvc_dual, kvc_src):
- '''
- ✨ add clean src kv cache to dual cache dict
- '''
- for b_idx in range(self.num_transformer_blocks):
- kvc_dual[b_idx].update({
- 'k_src_clean': kvc_src[b_idx]['k'],
- 'v_src_clean': kvc_src[b_idx]['v'],
- })
-
def _inject_masks_to_kv_cache(
self, kv_cache,
trg_fg_mask_cache=None, current_src_fg_mask=None,
@@ -654,12 +693,17 @@ class EditCausalInferencePipeline(torch.nn.Module):
})
def _kv_cache_to(self, kvc, device, low_memory):
+ '''
+ ✨ Offload the target KV cache while the dual cache already holds a copy.
+ Only "k"/"v" are moved: the bookkeeping tensors stay put so the surrounding
+ .item() calls keep working regardless of the offload state.
+ '''
if not low_memory:
return
for itm in kvc:
- for k, v in itm.items():
- if isinstance(v, torch.Tensor):
- v.to(device)
+ for key in ("k", "v"):
+ if isinstance(itm.get(key, None), torch.Tensor):
+ itm[key] = itm[key].to(device)
def _register_crossattn_enhancement(self, crossattn_cache, fg_indices, fg_boost_factor=1.0, layers=range(30), current_src_fg_mask=None):
@@ -736,24 +780,43 @@ class EditCausalInferencePipeline(torch.nn.Module):
):
if reuse_noise_temporal_mean:
self.noise_temporal_mean = dict()
- self.noise_temporal_mean_fg = dict()
- self.noise_temporal_mean_bg = dict()
else:
self.noise_temporal_mean = None
- self.noise_temporal_mean_fg = None
- self.noise_temporal_mean_bg = None
def _reuse_noise_statistics(
- self, noise: torch.Tensor, step_idx: int,
- fg_mask=None,
- alpha_prog=2,
+ self, noise: torch.Tensor, step_idx: int,
+ fg_mask=None, alpha_prog=2,
):
- if self.noise_temporal_mean is not None:
- if step_idx not in self.noise_temporal_mean.keys():
- self.noise_temporal_mean[step_idx] = noise
- else:
- noise = self.noise_temporal_mean[step_idx].flip(1) * alpha_prog / (1 + alpha_prog ** 2) ** 0.5 + \
- noise * 1 / (1 + alpha_prog ** 2) ** 0.5
- self.noise_temporal_mean[step_idx] = noise
+ '''
+ ✨ Temporally correlated noise across chunks. alpha_prog sets the correlation
+ with the previous chunk's noise (alpha=2 -> corr 2/sqrt(5) ~= 0.894).
+
+ When self.noise_alpha_fg is set and fg_mask is given, editing regions use that
+ (lower) correlation instead, so randomness is preserved where the edit needs it
+ (cf. Sec. 4.4: "randomness in editing-related regions remains beneficial").
+ Leaving self.noise_alpha_fg as None reproduces the original uniform behaviour.
+
+ noise: [B, F, C, H, W]
+ fg_mask: [B, F, H, W] bool
+ '''
+ if self.noise_temporal_mean is None:
+ return noise
+ if step_idx not in self.noise_temporal_mean.keys():
+ self.noise_temporal_mean[step_idx] = noise
+ return noise
+
+ prev = self.noise_temporal_mean[step_idx].flip(1)
+
+ def _mix(alpha):
+ scale = (1 + alpha ** 2) ** 0.5
+ return prev * alpha / scale + noise / scale
+
+ noise = _mix(alpha_prog)
+
+ alpha_fg = getattr(self, "noise_alpha_fg", None)
+ if (alpha_fg is not None) and (fg_mask is not None):
+ m = fg_mask.unsqueeze(2).to(noise.dtype) # [B, F, 1, H, W]
+ noise = noise * (1 - m) + _mix(alpha_fg) * m
+ self.noise_temporal_mean[step_idx] = noise
return noise
diff --git a/Self-Forcing_StreamEdit/inference_edit_streamedit.py b/Self-Forcing_StreamEdit/inference_edit_streamedit.py
index 69abbb1..d6a9529 100644
--- a/Self-Forcing_StreamEdit/inference_edit_streamedit.py
+++ b/Self-Forcing_StreamEdit/inference_edit_streamedit.py
@@ -66,6 +66,8 @@ def load_pipe(args):
config['model_kwargs']['timestep_shift'] = args.flow_shift
config['model_kwargs']['sink_size'] = getattr(args, 'sink_size', 0)
config['denoising_step_list'] = np.arange(1000, 0, -1000 / args.step).astype(int).tolist()
+ config['noise_alpha_fg'] = args.noise_alpha_fg
+ config['dump_masks_dir'] = args.dump_masks_dir
# Initialize pipeline, few-step method is unimplemented
pipeline = EditCausalInferencePipeline(config, device=device)
@@ -101,6 +103,12 @@ if __name__ == '__main__':
# hyper-parameters
parser.add_argument("--fg_boost_factor", type=float, default=4.0, help='CrossAttn Boosting')
parser.add_argument("--blend_power", type=float, default=2.0, help='rho')
+ parser.add_argument("--dump_masks_dir", type=str, default=None,
+ help='write per-chunk cross-attention masks here (PNG)')
+ parser.add_argument("--noise_alpha_fg", type=float, default=None,
+ help='temporal-noise correlation inside editing regions; '
+ 'None (default) keeps the original uniform correlation, '
+ '0 fully decorrelates the foreground across chunks')
# model settings
parser.add_argument("--step", type=int, default=15, help='1~1000')
diff --git a/Self-Forcing_StreamEdit/pipeline/edit_causal_inference.py b/Self-Forcing_StreamEdit/pipeline/edit_causal_inference.py
index bd6b9e3..d0d137c 100644
--- a/Self-Forcing_StreamEdit/pipeline/edit_causal_inference.py
+++ b/Self-Forcing_StreamEdit/pipeline/edit_causal_inference.py
@@ -41,6 +41,11 @@ class EditCausalInferencePipeline(torch.nn.Module):
self.frame_seq_length = 1560
self.args = args
+ # ✨ optional lower temporal-noise correlation inside editing regions;
+ # None keeps the original uniform correlation
+ self.noise_alpha_fg = getattr(args, "noise_alpha_fg", None)
+ # ✨ optional directory for per-chunk mask dumps (looking, not measuring)
+ self.dump_masks_dir = getattr(args, "dump_masks_dir", None)
self.num_frame_per_block = getattr(args, "num_frame_per_block", 1)
self.independent_first_frame = args.independent_first_frame
self.local_attn_size = self.generator.model.local_attn_size
@@ -382,10 +387,12 @@ class EditCausalInferencePipeline(torch.nn.Module):
# Step 3: Temporal denoising loop
denoising_step_list = self.denoising_step_list
+ _dump_chunk_idx = -1
all_num_frames = [self.num_frame_per_block] * num_blocks
if independent_first_frame and trg_initial_latent is None:
all_num_frames = [1] + all_num_frames
for current_num_frames in tqdm(all_num_frames):
+ _dump_chunk_idx += 1
if profile:
block_start.record()
@@ -401,7 +408,11 @@ class EditCausalInferencePipeline(torch.nn.Module):
# obtain currently inprocessed kv_cache for dual branch
shared_dict_dual = dict()
+ self._kv_cache_to(kv_cache_trg, 'cuda', low_memory)
kv_cache_dual = self._concat_kv_cache(kv_cache_src, kv_cache_trg, shared_dict=shared_dict_dual)
+ # the dual cache now holds a copy of the target cache, so the target cache
+ # can be offloaded for the whole spatial denoising loop (the memory peak)
+ self._kv_cache_to(kv_cache_trg, 'cpu', low_memory)
#✨ forward clean source video to get source mask, and store into kv_cache
self._register_crossattn_mask_gatherer(crossattn_cache_src, tok_src, layers=mask_layers, fg_scale=fg_scale)
@@ -498,6 +509,8 @@ class EditCausalInferencePipeline(torch.nn.Module):
crossattn_cache_dual, size=(current_num_frames, height, width), scale_factor=16
)
inloop_trg_fg_mask_bin = inloop_src_trg_fg_mask_bin.chunk(2, dim=0)[1]
+ self._dump_masks(_dump_chunk_idx, src_map=src_fg_mask_map,
+ vis_bin=mask_bin_vis, vis_soft=mask_soft_vis)
# inject union of origin src and in-processing trg masks to kv_cache
inloop_trg_fg_mask = inloop_trg_fg_mask_bin | src_fg_mask_bin
self._inject_masks_to_kv_cache(
@@ -575,6 +588,42 @@ class EditCausalInferencePipeline(torch.nn.Module):
return video
+ def _dump_masks(self, chunk_idx, src_map=None, vis_bin=None, vis_soft=None):
+ '''
+ ✨ Write the masks this chunk actually used to self.dump_masks_dir.
+ Nothing here is recomputed: mask_soft_vis / mask_bin_vis are already
+ produced (at full 480x832) by _aggregate_crossattn_mask and were
+ previously discarded. Row order in vis_* is [src, trg].
+ '''
+ d = getattr(self, "dump_masks_dir", None)
+ if not d:
+ return
+ import numpy as np
+ from PIL import Image
+ os.makedirs(d, exist_ok=True)
+
+ def save(arr, name):
+ a = arr.detach().float().cpu().numpy()
+ a = (a - a.min()) / (a.max() - a.min() + 1e-8) if a.max() > a.min() else a * 0
+ for f in range(a.shape[0]):
+ Image.fromarray((a[f] * 255).astype("uint8")).save(
+ os.path.join(d, "c%03d_f%d_%s.png" % (chunk_idx, f, name)))
+
+ if src_map is not None: # M^src, the reliable floor
+ m = src_map[0]
+ if m.shape[-1] < 400: # latent res -> video res
+ m = F.interpolate(m.float().unsqueeze(0), scale_factor=16,
+ mode="nearest").squeeze(0) > 0.5
+ save(m, "Msrc")
+ if vis_bin is not None: # [2B, F, H, W] = [src, trg]
+ save(vis_bin[0], "bin_src")
+ if vis_bin.shape[0] > 1:
+ save(vis_bin[1], "bin_trg")
+ if vis_soft is not None:
+ save(vis_soft[0], "soft_src")
+ if vis_soft.shape[0] > 1:
+ save(vis_soft[1], "soft_trg")
+
def _initialize_kv_cache(self, batch_size, dtype, device):
"""
Initialize a Per-GPU KV cache for the Wan model.
@@ -667,24 +716,14 @@ class EditCausalInferencePipeline(torch.nn.Module):
index_kvc = kvc_1
for b_idx in range(self.num_transformer_blocks):
kv_cache1.append({
- "k": torch.cat((kvc_1[b_idx]["k"], kvc_2[b_idx]["k"]), dim=0).clone(),
- "v": torch.cat((kvc_1[b_idx]["v"], kvc_2[b_idx]["v"]), dim=0).clone(),
+ "k": torch.cat((kvc_1[b_idx]["k"], kvc_2[b_idx]["k"]), dim=0),
+ "v": torch.cat((kvc_1[b_idx]["v"], kvc_2[b_idx]["v"]), dim=0),
"global_end_index": index_kvc[b_idx]["global_end_index"].clone(),
"local_end_index": index_kvc[b_idx]["local_end_index"].clone(),
"shared_dict": shared_dict,
})
return kv_cache1
- def _append_clean_src_kv_cache(self, kvc_dual, kvc_src):
- '''
- ✨ add clean src kv cache to dual cache dict
- '''
- for b_idx in range(self.num_transformer_blocks):
- kvc_dual[b_idx].update({
- 'k_src_clean': kvc_src[b_idx]['k'],
- 'v_src_clean': kvc_src[b_idx]['v'],
- })
-
def _inject_masks_to_kv_cache(
self, kv_cache,
trg_fg_mask_cache=None, current_src_fg_mask=None,
@@ -701,12 +740,17 @@ class EditCausalInferencePipeline(torch.nn.Module):
})
def _kv_cache_to(self, kvc, device, low_memory):
+ '''
+ ✨ Offload the target KV cache while the dual cache already holds a copy.
+ Only "k"/"v" are moved: the bookkeeping tensors stay put so the surrounding
+ .item() calls keep working regardless of the offload state.
+ '''
if not low_memory:
return
for itm in kvc:
- for k, v in itm.items():
- if isinstance(v, torch.Tensor):
- v.to(device)
+ for key in ("k", "v"):
+ if isinstance(itm.get(key, None), torch.Tensor):
+ itm[key] = itm[key].to(device)
def _register_crossattn_enhancement(self, crossattn_cache, fg_indices, fg_boost_factor=1.0, layers=range(30), current_src_fg_mask=None):
@@ -783,24 +827,43 @@ class EditCausalInferencePipeline(torch.nn.Module):
):
if reuse_noise_temporal_mean:
self.noise_temporal_mean = dict()
- self.noise_temporal_mean_fg = dict()
- self.noise_temporal_mean_bg = dict()
else:
self.noise_temporal_mean = None
- self.noise_temporal_mean_fg = None
- self.noise_temporal_mean_bg = None
def _reuse_noise_statistics(
- self, noise: torch.Tensor, step_idx: int,
- ema_factor: float = 0.5, fg_mask=None,
- alpha_prog=2, alpha_mixed=1,
+ self, noise: torch.Tensor, step_idx: int,
+ fg_mask=None, alpha_prog=2,
):
- if self.noise_temporal_mean is not None:
- if step_idx not in self.noise_temporal_mean.keys():
- self.noise_temporal_mean[step_idx] = noise
- else:
- noise = self.noise_temporal_mean[step_idx].flip(1) * alpha_prog / (1 + alpha_prog ** 2) ** 0.5 + \
- noise * 1 / (1 + alpha_prog ** 2) ** 0.5
- self.noise_temporal_mean[step_idx] = noise
-
+ '''
+ ✨ Temporally correlated noise across chunks. alpha_prog sets the correlation
+ with the previous chunk's noise (alpha=2 -> corr 2/sqrt(5) ~= 0.894).
+
+ When self.noise_alpha_fg is set and fg_mask is given, editing regions use that
+ (lower) correlation instead, so randomness is preserved where the edit needs it
+ (cf. Sec. 4.4: "randomness in editing-related regions remains beneficial").
+ Leaving self.noise_alpha_fg as None reproduces the original uniform behaviour.
+
+ noise: [B, F, C, H, W]
+ fg_mask: [B, F, H, W] bool
+ '''
+ if self.noise_temporal_mean is None:
+ return noise
+ if step_idx not in self.noise_temporal_mean.keys():
+ self.noise_temporal_mean[step_idx] = noise
+ return noise
+
+ prev = self.noise_temporal_mean[step_idx].flip(1)
+
+ def _mix(alpha):
+ scale = (1 + alpha ** 2) ** 0.5
+ return prev * alpha / scale + noise / scale
+
+ noise = _mix(alpha_prog)
+
+ alpha_fg = getattr(self, "noise_alpha_fg", None)
+ if (alpha_fg is not None) and (fg_mask is not None):
+ m = fg_mask.unsqueeze(2).to(noise.dtype) # [B, F, 1, H, W]
+ noise = noise * (1 - m) + _mix(alpha_fg) * m
+
+ self.noise_temporal_mean[step_idx] = noise
return noise
\ No newline at end of file