jbilcke-hf HF staff commited on
Commit
cdf6b7a
·
verified ·
1 Parent(s): 28747d9

Update handler.py

Browse files
Files changed (1) hide show
  1. handler.py +7 -2
handler.py CHANGED
@@ -7,6 +7,7 @@ import random
7
  import traceback
8
  import torch
9
  import os
 
10
 
11
  # note: there is no HunyuanImageToVideoPipeline yet in Diffusers
12
  from diffusers import HunyuanVideoPipeline, HunyuanVideoTransformer3DModel, FasterCacheConfig
@@ -276,7 +277,7 @@ class EndpointHandler:
276
  #else:
277
  # disable_teacache(self.pipeline.transformer)
278
 
279
- with torch.inference_mode():
280
 
281
  # Prepare generation parameters
282
  generation_kwargs = {
@@ -360,7 +361,11 @@ class EndpointHandler:
360
  asyncio.set_event_loop(loop)
361
 
362
  video_uri, metadata = loop.run_until_complete(self.process_frames(frames, config))
363
-
 
 
 
 
364
  return {
365
  "video": video_uri,
366
  "content-type": "video/mp4",
 
7
  import traceback
8
  import torch
9
  import os
10
+ import gc
11
 
12
  # note: there is no HunyuanImageToVideoPipeline yet in Diffusers
13
  from diffusers import HunyuanVideoPipeline, HunyuanVideoTransformer3DModel, FasterCacheConfig
 
277
  #else:
278
  # disable_teacache(self.pipeline.transformer)
279
 
280
+ with torch.amp.autocast_mode.autocast('cuda', torch.bfloat16), torch.no_grad(), torch.inference_mode():
281
 
282
  # Prepare generation parameters
283
  generation_kwargs = {
 
361
  asyncio.set_event_loop(loop)
362
 
363
  video_uri, metadata = loop.run_until_complete(self.process_frames(frames, config))
364
+
365
+ torch.cuda.empty_cache()
366
+ torch.cuda.reset_peak_memory_stats()
367
+ gc.collect()
368
+
369
  return {
370
  "video": video_uri,
371
  "content-type": "video/mp4",