Skip to content

Commit 74c70a7

Browse files
committed
Remaining local-variable device cleanup
1 parent 130b0ed commit 74c70a7

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/diffusers/modular_pipelines/cosmos/decoders.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def intermediate_outputs(self) -> list[OutputParam]:
4747
def __call__(self, components: Cosmos3OmniModularPipeline, state: PipelineState) -> PipelineState:
4848
block_state = self.get_block_state(state)
4949

50-
block_state.device = components._execution_device
50+
device = components._execution_device
5151

5252
if block_state.output_type == "latent":
5353
block_state.videos = block_state.latents
@@ -69,7 +69,7 @@ def __call__(self, components: Cosmos3OmniModularPipeline, state: PipelineState)
6969
"(or pass your own), or opt out explicitly with `pipe.disable_safety_checker()`."
7070
)
7171
block_state.videos = components._apply_video_safety_check(
72-
block_state.videos, output_type=block_state.output_type, device=block_state.device
72+
block_state.videos, output_type=block_state.output_type, device=device
7373
)
7474

7575
self.set_block_state(state, block_state)

src/diffusers/modular_pipelines/cosmos/encoders.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ def intermediate_outputs(self) -> list[OutputParam]:
284284
def __call__(self, components: Cosmos3OmniModularPipeline, state: PipelineState) -> PipelineState:
285285
block_state = self.get_block_state(state)
286286

287-
block_state.device = components._execution_device
288-
block_state.dtype = components.transformer.dtype
287+
device = components._execution_device
288+
dtype = components.transformer.dtype
289289

290290
if block_state.image is None:
291291
raise ValueError("`Cosmos3ImageVaeEncoderStep` requires an `image` input.")
@@ -304,16 +304,16 @@ def __call__(self, components: Cosmos3OmniModularPipeline, state: PipelineState)
304304

305305
conditioning_frame_2d = components.video_processor.preprocess(
306306
block_state.image, height=block_state.height, width=block_state.width
307-
).to(device=block_state.device, dtype=block_state.dtype)
307+
).to(device=device, dtype=dtype)
308308

309309
vision_tensor = torch.zeros(
310310
1,
311311
3,
312312
block_state.num_frames,
313313
block_state.height,
314314
block_state.width,
315-
dtype=block_state.dtype,
316-
device=block_state.device,
315+
dtype=dtype,
316+
device=device,
317317
)
318318
vision_tensor[:, :, 0] = conditioning_frame_2d
319319
vision_tensor[:, :, 1:] = conditioning_frame_2d.unsqueeze(2).expand(-1, -1, block_state.num_frames - 1, -1, -1)
@@ -366,8 +366,8 @@ def intermediate_outputs(self) -> list[OutputParam]:
366366
def __call__(self, components: Cosmos3OmniModularPipeline, state: PipelineState) -> PipelineState:
367367
block_state = self.get_block_state(state)
368368

369-
block_state.device = components._execution_device
370-
block_state.dtype = components.transformer.dtype
369+
device = components._execution_device
370+
dtype = components.transformer.dtype
371371

372372
if block_state.video is None:
373373
raise ValueError("`Cosmos3VideoVaeEncoderStep` requires a `video` input.")
@@ -410,7 +410,7 @@ def __call__(self, components: Cosmos3OmniModularPipeline, state: PipelineState)
410410
condition_indexes_vision = indexes
411411
conditioning_frames_3d = components.video_processor.preprocess_video(
412412
block_state.video, height=block_state.height, width=block_state.width
413-
).to(device=block_state.device, dtype=block_state.dtype)
413+
).to(device=device, dtype=dtype)
414414
temporal_compression = int(components.vae.config.scale_factor_temporal)
415415
max_cond_frames = max(condition_indexes_vision) * temporal_compression + 1
416416
if block_state.condition_video_keep == "first":
@@ -424,8 +424,8 @@ def __call__(self, components: Cosmos3OmniModularPipeline, state: PipelineState)
424424
block_state.num_frames,
425425
block_state.height,
426426
block_state.width,
427-
dtype=block_state.dtype,
428-
device=block_state.device,
427+
dtype=dtype,
428+
device=device,
429429
)
430430
t_fill = min(conditioning_frames_3d.shape[2], block_state.num_frames)
431431
vision_tensor[:, :, :t_fill] = conditioning_frames_3d[:, :, :t_fill]
@@ -482,8 +482,8 @@ def intermediate_outputs(self) -> list[OutputParam]:
482482
def __call__(self, components: Cosmos3OmniModularPipeline, state: PipelineState) -> PipelineState:
483483
block_state = self.get_block_state(state)
484484

485-
block_state.device = components._execution_device
486-
block_state.dtype = components.vae.dtype
485+
device = components._execution_device
486+
dtype = components.vae.dtype
487487

488488
action = block_state.action
489489
target_frames = action.chunk_size + 1
@@ -492,8 +492,8 @@ def __call__(self, components: Cosmos3OmniModularPipeline, state: PipelineState)
492492
conditioning_clip,
493493
action.resolution_tier,
494494
target_frames,
495-
device=block_state.device,
496-
dtype=block_state.dtype,
495+
device=device,
496+
dtype=dtype,
497497
)
498498

499499
if action.mode == "forward_dynamics":

0 commit comments

Comments
 (0)