Upload folder using huggingface_hub
Browse files- .gitattributes +3 -0
- config.json +32 -0
- diffusion_pytorch_model.safetensors +3 -0
- handler.py +64 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
images/fix-fp16.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
images/fix-fp32.png filter=lfs diff=lfs merge=lfs -text
|
38 |
+
images/orig-fp32.png filter=lfs diff=lfs merge=lfs -text
|
config.json
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_class_name": "AutoencoderKLHunyuanVideo",
|
3 |
+
"_diffusers_version": "0.32.0.dev0",
|
4 |
+
"act_fn": "silu",
|
5 |
+
"block_out_channels": [
|
6 |
+
128,
|
7 |
+
256,
|
8 |
+
512,
|
9 |
+
512
|
10 |
+
],
|
11 |
+
"down_block_types": [
|
12 |
+
"HunyuanVideoDownBlock3D",
|
13 |
+
"HunyuanVideoDownBlock3D",
|
14 |
+
"HunyuanVideoDownBlock3D",
|
15 |
+
"HunyuanVideoDownBlock3D"
|
16 |
+
],
|
17 |
+
"in_channels": 3,
|
18 |
+
"latent_channels": 16,
|
19 |
+
"layers_per_block": 2,
|
20 |
+
"mid_block_add_attention": true,
|
21 |
+
"norm_num_groups": 32,
|
22 |
+
"out_channels": 3,
|
23 |
+
"scaling_factor": 0.476986,
|
24 |
+
"spatial_compression_ratio": 8,
|
25 |
+
"temporal_compression_ratio": 4,
|
26 |
+
"up_block_types": [
|
27 |
+
"HunyuanVideoUpBlock3D",
|
28 |
+
"HunyuanVideoUpBlock3D",
|
29 |
+
"HunyuanVideoUpBlock3D",
|
30 |
+
"HunyuanVideoUpBlock3D"
|
31 |
+
]
|
32 |
+
}
|
diffusion_pytorch_model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7c68a6295f9034a88225fbafb1f3258291a08d57a1fdb938233fa57b1b8f4883
|
3 |
+
size 985943868
|
handler.py
ADDED
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, List, Any
|
2 |
+
import torch
|
3 |
+
from base64 import b64decode
|
4 |
+
from diffusers import AutoencoderKLHunyuanVideo
|
5 |
+
from diffusers.video_processor import VideoProcessor
|
6 |
+
from diffusers.utils import export_to_video
|
7 |
+
|
8 |
+
|
9 |
+
class EndpointHandler:
|
10 |
+
def __init__(self, path=""):
|
11 |
+
self.device = "cpu"
|
12 |
+
self.dtype = torch.float32
|
13 |
+
self.vae = (
|
14 |
+
AutoencoderKLHunyuanVideo.from_pretrained(
|
15 |
+
path, subfolder="vae", torch_dtype=self.dtype
|
16 |
+
)
|
17 |
+
.to(self.device, self.dtype)
|
18 |
+
.eval()
|
19 |
+
)
|
20 |
+
|
21 |
+
self.vae_scale_factor_spatial = self.vae.spatial_compression_ratio
|
22 |
+
self.video_processor = VideoProcessor(
|
23 |
+
vae_scale_factor=self.vae_scale_factor_spatial
|
24 |
+
)
|
25 |
+
|
26 |
+
@torch.no_grad()
|
27 |
+
def __call__(self, data: Any) -> List[List[Dict[str, float]]]:
|
28 |
+
"""
|
29 |
+
Args:
|
30 |
+
data (:obj:):
|
31 |
+
includes the input data and the parameters for the inference.
|
32 |
+
"""
|
33 |
+
tensor = data["inputs"]
|
34 |
+
tensor = b64decode(tensor.encode("utf-8"))
|
35 |
+
parameters = data.get("parameters", {})
|
36 |
+
if "shape" not in parameters:
|
37 |
+
raise ValueError("Expected `shape` in parameters.")
|
38 |
+
if "dtype" not in parameters:
|
39 |
+
raise ValueError("Expected `dtype` in parameters.")
|
40 |
+
|
41 |
+
DTYPE_MAP = {
|
42 |
+
"float16": torch.float16,
|
43 |
+
"float32": torch.float32,
|
44 |
+
"bfloat16": torch.bfloat16,
|
45 |
+
}
|
46 |
+
|
47 |
+
shape = parameters.get("shape")
|
48 |
+
dtype = DTYPE_MAP.get(parameters.get("dtype"))
|
49 |
+
tensor = torch.frombuffer(bytearray(tensor), dtype=dtype).reshape(shape)
|
50 |
+
|
51 |
+
tensor = tensor.to(self.device, self.dtype)
|
52 |
+
|
53 |
+
tensor = tensor / self.vae.config.scaling_factor
|
54 |
+
|
55 |
+
with torch.no_grad():
|
56 |
+
frames = self.vae.decode(tensor, return_dict=False)[0]
|
57 |
+
|
58 |
+
frames = self.video_processor.postprocess_video(frames, output_type="pil")[0]
|
59 |
+
|
60 |
+
path = export_to_video(frames, fps=15)
|
61 |
+
with open(path, "rb") as f:
|
62 |
+
video = f.read()
|
63 |
+
|
64 |
+
return video
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
huggingface_hub
|
2 |
+
diffusers
|
3 |
+
imageio-ffmpeg
|