sayakpaul HF Staff commited on
Commit
fd6ab1f
·
verified ·
1 Parent(s): c88a78a

Upload folder using huggingface_hub

Browse files
.ruff_cache/.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ # Automatically created by ruff.
2
+ *
.ruff_cache/0.7.1/3405182261834977827 ADDED
Binary file (382 Bytes). View file
 
.ruff_cache/CACHEDIR.TAG ADDED
@@ -0,0 +1 @@
 
 
1
+ Signature: 8a477f597d28d172789f06886806bc55
before_denoise.py CHANGED
@@ -37,17 +37,11 @@ class ChronoEditSetTimestepsStep(ModularPipelineBlocks):
37
 
38
  @property
39
  def expected_components(self) -> List[ComponentSpec]:
40
- return [
41
- ComponentSpec("scheduler", UniPCMultistepScheduler)
42
- ]
43
 
44
  @property
45
  def inputs(self) -> List[InputParam]:
46
- return [
47
- InputParam("num_inference_steps", default=50),
48
- InputParam("timesteps"),
49
- InputParam("sigmas")
50
- ]
51
 
52
  @property
53
  def intermediate_outputs(self) -> List[OutputParam]:
@@ -72,7 +66,7 @@ class ChronoEditSetTimestepsStep(ModularPipelineBlocks):
72
  block_state.timesteps,
73
  block_state.sigmas,
74
  )
75
-
76
  self.set_block_state(state, block_state)
77
  return components, state
78
 
@@ -186,18 +180,18 @@ class ChronoEditPrepareLatentStep(ModularPipelineBlocks):
186
  )
187
  mask_lat_size = mask_lat_size.transpose(1, 2)
188
  mask_lat_size = mask_lat_size.to(latent_condition.device)
189
-
190
  return latents, torch.concat([mask_lat_size, latent_condition], dim=1)
191
 
192
  @torch.no_grad()
193
  def __call__(self, components: ModularPipeline, state: PipelineState) -> PipelineState:
194
  block_state = self.get_block_state(state)
195
-
196
  self.check_inputs(block_state.height, block_state.width)
197
 
198
  block_state.device = components._execution_device
199
  block_state.num_channels_latents = components.num_channels_latents
200
-
201
  batch_size = block_state.batch_size * block_state.num_videos_per_prompt
202
  block_state.latents, block_state.condition = self.prepare_latents(
203
  components,
@@ -214,5 +208,5 @@ class ChronoEditPrepareLatentStep(ModularPipelineBlocks):
214
  )
215
 
216
  self.set_block_state(state, block_state)
217
-
218
  return components, state
 
37
 
38
  @property
39
  def expected_components(self) -> List[ComponentSpec]:
40
+ return [ComponentSpec("scheduler", UniPCMultistepScheduler)]
 
 
41
 
42
  @property
43
  def inputs(self) -> List[InputParam]:
44
+ return [InputParam("num_inference_steps", default=50), InputParam("timesteps"), InputParam("sigmas")]
 
 
 
 
45
 
46
  @property
47
  def intermediate_outputs(self) -> List[OutputParam]:
 
66
  block_state.timesteps,
67
  block_state.sigmas,
68
  )
69
+
70
  self.set_block_state(state, block_state)
71
  return components, state
72
 
 
180
  )
181
  mask_lat_size = mask_lat_size.transpose(1, 2)
182
  mask_lat_size = mask_lat_size.to(latent_condition.device)
183
+
184
  return latents, torch.concat([mask_lat_size, latent_condition], dim=1)
185
 
186
  @torch.no_grad()
187
  def __call__(self, components: ModularPipeline, state: PipelineState) -> PipelineState:
188
  block_state = self.get_block_state(state)
189
+
190
  self.check_inputs(block_state.height, block_state.width)
191
 
192
  block_state.device = components._execution_device
193
  block_state.num_channels_latents = components.num_channels_latents
194
+
195
  batch_size = block_state.batch_size * block_state.num_videos_per_prompt
196
  block_state.latents, block_state.condition = self.prepare_latents(
197
  components,
 
208
  )
209
 
210
  self.set_block_state(state, block_state)
211
+
212
  return components, state
decoders.py CHANGED
@@ -14,14 +14,12 @@
14
  # limitations under the License.
15
 
16
  from diffusers.configuration_utils import FrozenDict
17
- from diffusers.modular_pipelines import (
18
- ModularPipelineBlocks, ComponentSpec, InputParam, OutputParam, PipelineState
19
- )
20
  from typing import List, Union
21
  from diffusers import AutoencoderKLWan
22
  from diffusers.video_processor import VideoProcessor
23
  import torch
24
- import PIL
25
  import numpy as np
26
 
27
 
@@ -93,4 +91,4 @@ class ChronoEditDecodeStep(ModularPipelineBlocks):
93
 
94
  self.set_block_state(state, block_state)
95
 
96
- return components, state
 
14
  # limitations under the License.
15
 
16
  from diffusers.configuration_utils import FrozenDict
17
+ from diffusers.modular_pipelines import ModularPipelineBlocks, ComponentSpec, InputParam, OutputParam, PipelineState
 
 
18
  from typing import List, Union
19
  from diffusers import AutoencoderKLWan
20
  from diffusers.video_processor import VideoProcessor
21
  import torch
22
+ import PIL
23
  import numpy as np
24
 
25
 
 
91
 
92
  self.set_block_state(state, block_state)
93
 
94
+ return components, state
demo.png CHANGED

Git LFS Details

  • SHA256: c324784d3448ecf10df38c9a097d034c701f3edf6d0917f5adab86ffc2220934
  • Pointer size: 131 Bytes
  • Size of remote file: 906 kB

Git LFS Details

  • SHA256: b29c5b280640a727812d58ace45b0ab06cbdd68e2e1cbdef3b3b3d5afd6b8436
  • Pointer size: 131 Bytes
  • Size of remote file: 897 kB
denoise.py CHANGED
@@ -190,7 +190,7 @@ class ChronoEditDenoiseLoopWrapper(LoopSequentialPipelineBlocks):
190
  @torch.no_grad()
191
  def __call__(self, components: ModularPipeline, state: PipelineState) -> PipelineState:
192
  block_state = self.get_block_state(state)
193
-
194
  block_state.num_warmup_steps = max(
195
  len(block_state.timesteps) - block_state.num_inference_steps * components.scheduler.order, 0
196
  )
 
190
  @torch.no_grad()
191
  def __call__(self, components: ModularPipeline, state: PipelineState) -> PipelineState:
192
  block_state = self.get_block_state(state)
193
+
194
  block_state.num_warmup_steps = max(
195
  len(block_state.timesteps) - block_state.num_inference_steps * components.scheduler.order, 0
196
  )
encoders.py CHANGED
@@ -88,7 +88,7 @@ class ChronoEditProcessImageStep(ModularPipelineBlocks):
88
  def intermediate_outputs(self) -> List[OutputParam]:
89
  return [
90
  OutputParam("processed_image", type_hint=PipelineImageInput),
91
- OutputParam("image_embeds", type_hint=torch.Tensor)
92
  ]
93
 
94
  @property
@@ -118,7 +118,7 @@ class ChronoEditProcessImageStep(ModularPipelineBlocks):
118
  block_state.image_embeds = image_embeds.repeat(batch_size, 1, 1).to(torch.bfloat16)
119
 
120
  self.set_block_state(state, block_state)
121
-
122
  return components, state
123
 
124
 
 
88
  def intermediate_outputs(self) -> List[OutputParam]:
89
  return [
90
  OutputParam("processed_image", type_hint=PipelineImageInput),
91
+ OutputParam("image_embeds", type_hint=torch.Tensor),
92
  ]
93
 
94
  @property
 
118
  block_state.image_embeds = image_embeds.repeat(batch_size, 1, 1).to(torch.bfloat16)
119
 
120
  self.set_block_state(state, block_state)
121
+
122
  return components, state
123
 
124
 
example.py CHANGED
@@ -2,24 +2,22 @@
2
  Mimicked from https://huggingface.co/spaces/nvidia/ChronoEdit/blob/main/app.py
3
  """
4
 
5
- from diffusers.modular_pipelines import ModularPipelineBlocks, WanModularPipeline
6
  from diffusers.utils import load_image
7
  from diffusers import UniPCMultistepScheduler
8
- from modular_blocks import ChronoEditBlocks
9
  import torch
10
  from PIL import Image
11
 
12
- repo_id = "nvidia/ChronoEdit-14B-Diffusers"
13
- blocks = ChronoEditBlocks()
14
  pipe = WanModularPipeline(blocks, repo_id)
15
-
16
  pipe.load_components(
17
  trust_remote_code=True,
18
  device_map="cuda",
19
  torch_dtype={"default": torch.bfloat16, "image_encoder": torch.float32},
20
  )
21
  pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=2.0)
22
- pipe.load_lora_weights(repo_id, weight_name="lora/chronoedit_distill_lora.safetensors")
23
  pipe.fuse_lora(lora_scale=1.0)
24
 
25
  image = load_image("https://huggingface.co/spaces/nvidia/ChronoEdit/resolve/main/examples/3.png")
@@ -31,8 +29,9 @@ out = pipe(
31
  image=image,
32
  prompt=prompt, # todo: enhance prompt
33
  num_inference_steps=8, # todo: implement temporal reasoning
34
- num_frames=5, # https://huggingface.co/spaces/nvidia/ChronoEdit/blob/main/app.py#L152
35
  output_type="np",
 
36
  )
37
  frames = out.values["videos"][0]
38
  Image.fromarray((frames[-1] * 255).clip(0, 255).astype("uint8")).save("demo.png")
 
2
  Mimicked from https://huggingface.co/spaces/nvidia/ChronoEdit/blob/main/app.py
3
  """
4
 
5
+ from diffusers.modular_pipelines import WanModularPipeline, ModularPipelineBlocks
6
  from diffusers.utils import load_image
7
  from diffusers import UniPCMultistepScheduler
 
8
  import torch
9
  from PIL import Image
10
 
11
+ repo_id = "diffusers-internal-dev/chronoedit-modular"
12
+ blocks = ModularPipelineBlocks.from_pretrained(repo_id, trust_remote_code=True)
13
  pipe = WanModularPipeline(blocks, repo_id)
 
14
  pipe.load_components(
15
  trust_remote_code=True,
16
  device_map="cuda",
17
  torch_dtype={"default": torch.bfloat16, "image_encoder": torch.float32},
18
  )
19
  pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config, flow_shift=2.0)
20
+ pipe.load_lora_weights("nvidia/ChronoEdit-14B-Diffusers", weight_name="lora/chronoedit_distill_lora.safetensors")
21
  pipe.fuse_lora(lora_scale=1.0)
22
 
23
  image = load_image("https://huggingface.co/spaces/nvidia/ChronoEdit/resolve/main/examples/3.png")
 
29
  image=image,
30
  prompt=prompt, # todo: enhance prompt
31
  num_inference_steps=8, # todo: implement temporal reasoning
32
+ num_frames=5, # https://huggingface.co/spaces/nvidia/ChronoEdit/blob/main/app.py#L152
33
  output_type="np",
34
+ generator=torch.manual_seed(0),
35
  )
36
  frames = out.values["videos"][0]
37
  Image.fromarray((frames[-1] * 255).clip(0, 255).astype("uint8")).save("demo.png")
inputs.py CHANGED
@@ -86,11 +86,11 @@ class ChronoEditImageInputStep(ModularPipelineBlocks):
86
  block_state = self.get_block_state(state)
87
  image = block_state.image
88
  mod_value = components.vae_scale_factor_spatial * components.transformer.config.patch_size[1]
89
-
90
  width, height = calculate_dimensions(image, mod_value)
91
  block_state.image = image.resize((width, height))
92
- block_state.height = height
93
  block_state.width = width
94
-
95
  self.set_block_state(state, block_state)
96
  return components, state
 
86
  block_state = self.get_block_state(state)
87
  image = block_state.image
88
  mod_value = components.vae_scale_factor_spatial * components.transformer.config.patch_size[1]
89
+
90
  width, height = calculate_dimensions(image, mod_value)
91
  block_state.image = image.resize((width, height))
92
+ block_state.height = height
93
  block_state.width = width
94
+
95
  self.set_block_state(state, block_state)
96
  return components, state
upload_block.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers.modular_pipelines import WanModularPipeline
2
+
3
+ from modular_blocks import ChronoEditBlocks
4
+
5
+ repo_id = "nvidia/ChronoEdit-14B-Diffusers"
6
+ blocks = ChronoEditBlocks()
7
+
8
+ blocks.push_to_hub("diffusers-internal-dev/chronoedit-modular")
9
+
10
+ pipe = WanModularPipeline(blocks, repo_id)
11
+ pipe.push_to_hub("diffusers-internal-dev/chronoedit-modular")