meepmoo commited on
Commit
d82b5af
·
verified ·
1 Parent(s): 6adaaf1

Update worker_runpod.py

Browse files
Files changed (1) hide show
  1. worker_runpod.py +18 -16
worker_runpod.py CHANGED
@@ -71,22 +71,22 @@ def download_image(url, download_dir="/content"):
71
  # Usage
72
  # validation_image_start = values.get("validation_image_start", "https://example.com/path/to/image.png")
73
  # downloaded_image_path = download_image(validation_image_start)
74
- model_id = "/runpod-volume/model"
75
- transformer = CogVideoXTransformer3DModel.from_pretrained_2d(model_id, subfolder="transformer").to(torch.bfloat16)
 
76
 
77
- vae = AutoencoderKLCogVideoX.from_pretrained(model_id, subfolder="vae").to(torch.bfloat16)
78
 
79
- text_encoder = T5EncoderModel.from_pretrained(model_id, subfolder="text_encoder")
80
-
81
- sampler_dict = {
82
  "Euler": EulerDiscreteScheduler,
83
  "Euler A": EulerAncestralDiscreteScheduler,
84
  "DPM++": DPMSolverMultistepScheduler,
85
  "PNDM": PNDMScheduler,
86
  "DDIM_Cog": CogVideoXDDIMScheduler,
87
  "DDIM_Origin": DDIMScheduler,
88
- }
89
- scheduler = sampler_dict["DPM++"].from_pretrained(model_id, subfolder="scheduler")
90
 
91
  # Pipeline setup
92
  if transformer.config.in_channels != vae.config.latent_channels:
@@ -102,10 +102,12 @@ else:
102
  torch_dtype=torch.bfloat16
103
  )
104
 
105
- if low_gpu_memory_mode:
106
- pipeline.enable_sequential_cpu_offload()
107
- else:
108
- pipeline.enable_model_cpu_offload()
 
 
109
 
110
  @torch.inference_mode()
111
  def generate(input):
@@ -118,10 +120,11 @@ def generate(input):
118
  seed = values.get("seed", 42)
119
  num_inference_steps = values.get("num_inference_steps", 18)
120
  base_resolution = values.get("base_resolution", 512)
121
-
 
122
  video_length = values.get("video_length", 53)
123
  fps = values.get("fps", 10)
124
- lora_weight = values.get("lora_weight", 1.00)
125
  save_path = "samples"
126
  partial_video_length = values.get("partial_video_length", None)
127
  overlap_video_length = values.get("overlap_video_length", 4)
@@ -132,8 +135,7 @@ def generate(input):
132
 
133
  generator = torch.Generator(device="cuda").manual_seed(seed)
134
  print("Generator started")
135
- if lora_path is not None:
136
- pipeline = merge_lora(pipeline, lora_path, lora_weight)
137
 
138
  aspect_ratio_sample_size = {key : [x / 512 * base_resolution for x in ASPECT_RATIO_512[key]] for key in ASPECT_RATIO_512.keys()}
139
  start_img = Image.open(downloaded_image_path)
 
71
  # Usage
72
  # validation_image_start = values.get("validation_image_start", "https://example.com/path/to/image.png")
73
  # downloaded_image_path = download_image(validation_image_start)
74
+ with torch.inference_mode():
75
+ model_id = "/runpod-volume/model"
76
+ transformer = CogVideoXTransformer3DModel.from_pretrained_2d(model_id, subfolder="transformer").to(torch.bfloat16)
77
 
78
+ vae = AutoencoderKLCogVideoX.from_pretrained(model_id, subfolder="vae").to(torch.bfloat16)
79
 
80
+ text_encoder = T5EncoderModel.from_pretrained(model_id, subfolder="text_encoder")
81
+ sampler_dict = {
 
82
  "Euler": EulerDiscreteScheduler,
83
  "Euler A": EulerAncestralDiscreteScheduler,
84
  "DPM++": DPMSolverMultistepScheduler,
85
  "PNDM": PNDMScheduler,
86
  "DDIM_Cog": CogVideoXDDIMScheduler,
87
  "DDIM_Origin": DDIMScheduler,
88
+ }
89
+ scheduler = sampler_dict["DPM++"].from_pretrained(model_id, subfolder="scheduler")
90
 
91
  # Pipeline setup
92
  if transformer.config.in_channels != vae.config.latent_channels:
 
102
  torch_dtype=torch.bfloat16
103
  )
104
 
105
+ # if low_gpu_memory_mode:
106
+ # pipeline.enable_sequential_cpu_offload()
107
+ # else:
108
+ # pipeline.enable_model_cpu_offload()
109
+
110
+
111
 
112
  @torch.inference_mode()
113
  def generate(input):
 
120
  seed = values.get("seed", 42)
121
  num_inference_steps = values.get("num_inference_steps", 18)
122
  base_resolution = values.get("base_resolution", 512)
123
+ lora_weight = values.get("lora_weight", 1.00)
124
+ pipeline = merge_lora(pipeline, lora_path, lora_weight)
125
  video_length = values.get("video_length", 53)
126
  fps = values.get("fps", 10)
127
+
128
  save_path = "samples"
129
  partial_video_length = values.get("partial_video_length", None)
130
  overlap_video_length = values.get("overlap_video_length", 4)
 
135
 
136
  generator = torch.Generator(device="cuda").manual_seed(seed)
137
  print("Generator started")
138
+
 
139
 
140
  aspect_ratio_sample_size = {key : [x / 512 * base_resolution for x in ASPECT_RATIO_512[key]] for key in ASPECT_RATIO_512.keys()}
141
  start_img = Image.open(downloaded_image_path)