Skip to content

Commit 5642b1b

Browse files
Merge pull request #367 from AI-Hypercomputer:sagarchapara/wananimate-pipeline
PiperOrigin-RevId: 914377609
2 parents cc95c74 + eddfd4d commit 5642b1b

13 files changed

Lines changed: 4012 additions & 150 deletions
Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,347 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# This sentinel is a reminder to choose a real run name.
16+
run_name: ''
17+
18+
metrics_file: "" # for testing, local file that stores scalar metrics. If empty, no metrics are written.
19+
# If true save metrics such as loss and TFLOPS to GCS in {base_output_directory}/{run_name}/metrics/
20+
write_metrics: True
21+
22+
timing_metrics_file: "" # for testing, local file that stores function timing metrics such as state creation, compilation. If empty, no metrics are written.
23+
write_timing_metrics: True
24+
25+
gcs_metrics: False
26+
# If true save config to GCS in {base_output_directory}/{run_name}/
27+
save_config_to_gcs: False
28+
log_period: 100
29+
30+
pretrained_model_name_or_path: 'Wan-AI/Wan2.2-Animate-14B-Diffusers'
31+
model_name: wan2.2
32+
model_type: 'I2V'
33+
34+
# Overrides the transformer from pretrained_model_name_or_path
35+
wan_transformer_pretrained_model_name_or_path: ''
36+
37+
unet_checkpoint: ''
38+
revision: ''
39+
# This will convert the weights to this dtype.
40+
# When running inference on TPUv5e, use weights_dtype: 'bfloat16'
41+
weights_dtype: 'bfloat16'
42+
# This sets the layer's dtype in the model. Ex: nn.Dense(dtype=activations_dtype)
43+
activations_dtype: 'bfloat16'
44+
45+
# Replicates vae across devices instead of using the model's sharding annotations for sharding.
46+
replicate_vae: False
47+
# Number of devices to shard VAE spatial activations across. -1 uses all devices.
48+
vae_spatial: -1
49+
50+
# matmul and conv precision from https://jax.readthedocs.io/en/latest/jax.lax.html#jax.lax.Precision
51+
# Options are "DEFAULT", "HIGH", "HIGHEST"
52+
# fp32 activations and fp32 weights with HIGHEST will provide the best precision
53+
# at the cost of time.
54+
precision: "DEFAULT"
55+
# Use jax.lax.scan for transformer layers
56+
scan_layers: False
57+
58+
# if False state is not jitted and instead replicate is called. This is good for debugging on single host
59+
# It must be True for multi-host.
60+
jit_initializers: True
61+
62+
# Set true to load weights from pytorch
63+
from_pt: True
64+
split_head_dim: True
65+
attention: 'flash' # Supported attention: dot_product, flash, tokamax_flash, cudnn_flash_te, ring, tokamax_ring, ulysses, ulysses_custom
66+
use_base2_exp: True
67+
use_experimental_scheduler: True
68+
flash_min_seq_length: 4096
69+
# If mask_padding_tokens is True, we pass in segment ids to splash attention to avoid attending to padding tokens.
70+
# Else we do not pass in segment ids and on vpu bound hardware like trillium this is faster.
71+
# However, when padding tokens are significant, this will lead to worse quality and should be set to True.
72+
mask_padding_tokens: True
73+
# Maxdiffusion has 2 types of attention sharding strategies:
74+
# 1. attention_sharding_uniform = True : same sequence sharding rules applied for q in both (self and cross attention)
75+
# 2. attention_sharding_uniform = False : Heads are sharded uniformly across devices for self attention while sequence is sharded
76+
# in cross attention q.
77+
attention_sharding_uniform: True
78+
dropout: 0.0
79+
80+
# Tuned for 720p (720x1280), 81 frames, CP=8 on Trillium (32MB VMEM):
81+
# block_q=2048, block_kv=4096, block_kv_compute=1024
82+
# ~31% faster than default (512,512,512): 389s vs 508s at 40 steps
83+
flash_block_sizes: {
84+
"block_q" : 2048,
85+
"block_kv_compute" : 1024,
86+
"block_kv" : 4096,
87+
"block_q_dkv" : 512,
88+
"block_kv_dkv" : 512,
89+
"block_kv_dkv_compute" : 512,
90+
"block_q_dq" : 512,
91+
"block_kv_dq" : 512,
92+
"use_fused_bwd_kernel": False,
93+
}
94+
# Default smaller-shape block sizes:
95+
# flash_block_sizes: {
96+
# "block_q" : 512,
97+
# "block_kv_compute" : 512,
98+
# "block_kv" : 512,
99+
# "block_q_dkv" : 512,
100+
# "block_kv_dkv" : 512,
101+
# "block_kv_dkv_compute" : 512,
102+
# "block_q_dq" : 512,
103+
# "block_kv_dq" : 512,
104+
# "use_fused_bwd_kernel": False,
105+
# }
106+
# GroupNorm groups
107+
norm_num_groups: 32
108+
109+
# Text encoder training keys are unused by generate_wan_animate.py.
110+
train_text_encoder: False
111+
text_encoder_learning_rate: 4.25e-6
112+
113+
# Training loss keys are unused by generate_wan_animate.py.
114+
snr_gamma: -1.0
115+
116+
timestep_bias: {
117+
# a value of later will increase the frequency of the model's final training steps.
118+
# none, earlier, later, range
119+
strategy: "none",
120+
# multiplier for bias, a value of 2.0 will double the weight of the bias, 0.5 will halve it.
121+
multiplier: 1.0,
122+
# when using strategy=range, the beginning (inclusive) timestep to bias.
123+
begin: 0,
124+
# when using strategy=range, the final step (inclusive) to bias.
125+
end: 1000,
126+
# portion of timesteps to bias.
127+
# 0.5 will bias one half of the timesteps. Value of strategy determines
128+
# whether the biased portions are in the earlier or later timesteps.
129+
portion: 0.25
130+
}
131+
132+
# Override parameters from checkpoints's scheduler.
133+
diffusion_scheduler_config: {
134+
_class_name: 'FlaxEulerDiscreteScheduler',
135+
prediction_type: 'epsilon',
136+
rescale_zero_terminal_snr: False,
137+
timestep_spacing: 'trailing'
138+
}
139+
140+
# Output directory
141+
# Create a GCS bucket, e.g. my-maxtext-outputs and set this to "gs://my-maxtext-outputs/"
142+
base_output_directory: ""
143+
144+
# Hardware
145+
hardware: 'tpu' # Supported hardware types are 'tpu', 'gpu'
146+
skip_jax_distributed_system: False
147+
148+
# Parallelism
149+
mesh_axes: ['data', 'fsdp', 'context', 'tensor']
150+
151+
# batch : batch dimension of data and activations
152+
# hidden :
153+
# embed : attention qkv dense layer hidden dim named as embed
154+
# heads : attention head dim = num_heads * head_dim
155+
# length : attention sequence length
156+
# temb_in : dense.shape[0] of resnet dense before conv
157+
# out_c : dense.shape[1] of resnet dense before conv
158+
# out_channels : conv.shape[-1] activation
159+
# keep_1 : conv.shape[0] weight
160+
# keep_2 : conv.shape[1] weight
161+
# conv_in : conv.shape[2] weight
162+
# conv_out : conv.shape[-1] weight
163+
logical_axis_rules: [
164+
['batch', ['data', 'fsdp']],
165+
['activation_batch', ['data', 'fsdp']],
166+
['activation_self_attn_heads', ['context', 'tensor']],
167+
['activation_cross_attn_q_length', ['context', 'tensor']],
168+
['activation_length', 'context'],
169+
['activation_heads', 'tensor'],
170+
['mlp','tensor'],
171+
['embed', ['context', 'fsdp']],
172+
['heads', 'tensor'],
173+
['norm', 'tensor'],
174+
['conv_batch', ['data', 'context', 'fsdp']],
175+
['out_channels', 'tensor'],
176+
['conv_out', 'context'],
177+
]
178+
vae_logical_axis_rules: [
179+
['activation_batch', 'redundant'],
180+
['activation_length', 'vae_spatial'],
181+
['activation_heads', null],
182+
['activation_kv_length', null],
183+
['embed', null],
184+
['heads', null],
185+
['norm', null],
186+
['conv_batch', 'redundant'],
187+
['out_channels', 'vae_spatial'],
188+
['conv_out', 'vae_spatial'],
189+
['conv_in', 'vae_spatial'],
190+
]
191+
data_sharding: [['data', 'fsdp', 'context', 'tensor']]
192+
193+
# One axis for each parallelism type may hold a placeholder (-1)
194+
# value to auto-shard based on available slices and devices.
195+
# By default, product of the DCN axes should equal number of slices
196+
# and product of the ICI axes should equal number of devices per slice.
197+
dcn_data_parallelism: 1 # recommended DCN axis to be auto-sharded
198+
dcn_fsdp_parallelism: 1
199+
dcn_context_parallelism: -1
200+
dcn_tensor_parallelism: 1
201+
ici_data_parallelism: 1
202+
ici_fsdp_parallelism: 1
203+
ici_context_parallelism: -1 # recommended ICI axis to be auto-sharded
204+
ici_tensor_parallelism: 1
205+
206+
allow_split_physical_axes: False
207+
208+
# Dataset keys are kept for shared pyconfig compatibility.
209+
# They are not used by generate_wan_animate.py.
210+
dataset_name: ''
211+
train_split: 'train'
212+
dataset_type: 'tfrecord'
213+
cache_latents_text_encoder_outputs: True
214+
dataset_save_location: ''
215+
load_tfrecord_cached: True
216+
train_data_dir: ''
217+
dataset_config_name: ''
218+
jax_cache_dir: '.jax_cache'
219+
hf_data_dir: ''
220+
hf_train_files: ''
221+
hf_access_token: ''
222+
image_column: 'image'
223+
caption_column: 'text'
224+
resolution: 1024
225+
center_crop: False
226+
random_flip: False
227+
# If cache_latents_text_encoder_outputs is True
228+
# the num_proc is set to 1
229+
tokenize_captions_num_proc: 4
230+
transform_images_num_proc: 4
231+
reuse_example_batch: False
232+
enable_data_shuffling: True
233+
234+
# Defines the type of gradient checkpoint to enable.
235+
# NONE - means no gradient checkpoint
236+
# FULL - means full gradient checkpoint, whenever possible (minimum memory usage)
237+
# MATMUL_WITHOUT_BATCH - means gradient checkpoint for every linear/matmul operation,
238+
# except for ones that involve batch dimension - that means that all attention and projection
239+
# layers will have gradient checkpoint, but not the backward with respect to the parameters.
240+
# OFFLOAD_MATMUL_WITHOUT_BATCH - same as MATMUL_WITHOUT_BATCH but offload instead of recomputing.
241+
# CUSTOM - set names to offload and save.
242+
remat_policy: "NONE"
243+
# For CUSTOM policy set below, current annotations are for: attn_output, query_proj, key_proj, value_proj
244+
# xq_out, xk_out, ffn_activation
245+
names_which_can_be_saved: []
246+
names_which_can_be_offloaded: []
247+
248+
# checkpoint every number of samples, -1 means don't checkpoint.
249+
checkpoint_every: -1
250+
checkpoint_dir: ""
251+
# enables one replica to read the ckpt then broadcast to the rest
252+
enable_single_replica_ckpt_restoring: False
253+
254+
# Shared training keys are kept for shared pyconfig compatibility.
255+
learning_rate: 1.e-5
256+
scale_lr: False
257+
max_train_samples: -1
258+
# max_train_steps takes priority over num_train_epochs.
259+
max_train_steps: 1500
260+
num_train_epochs: 1
261+
seed: 0
262+
output_dir: 'wan-animate-outputs'
263+
per_device_batch_size: 0.125
264+
# If global_batch_size % jax.device_count is not 0, use FSDP sharding.
265+
global_batch_size: 0
266+
267+
# For creating tfrecords from dataset
268+
tfrecords_dir: ''
269+
no_records_per_shard: 0
270+
enable_eval_timesteps: False
271+
timesteps_list: [125, 250, 375, 500, 625, 750, 875]
272+
num_eval_samples: 420
273+
274+
warmup_steps_fraction: 0.1
275+
learning_rate_schedule_steps: -1 # By default the length of the schedule is set to the number of steps.
276+
save_optimizer: False
277+
278+
# However you may choose a longer schedule (learning_rate_schedule_steps > steps), in which case the training will end before
279+
# dropping fully down. Or you may choose a shorter schedule, where the unspecified steps will have a learning rate of 0.
280+
281+
# AdamW optimizer parameters
282+
adam_b1: 0.9 # Exponential decay rate to track the first moment of past gradients.
283+
adam_b2: 0.999 # Exponential decay rate to track the second moment of past gradients.
284+
adam_eps: 1.e-8 # A small constant applied to denominator outside of the square root.
285+
adam_weight_decay: 0 # AdamW Weight decay
286+
max_grad_norm: 1.0
287+
288+
enable_profiler: False
289+
# ML Diagnostics settings
290+
enable_ml_diagnostics: False
291+
profiler_gcs_path: ""
292+
enable_ondemand_xprof: False
293+
# Skip first n steps for profiling, to omit things like compilation and to give
294+
# the iteration time a chance to stabilize.
295+
skip_first_n_steps_for_profiler: 5
296+
profiler_steps: 10
297+
298+
# Enable JAX named scopes for detailed profiling and debugging
299+
# When enabled, adds named scopes around key operations in transformer and attention layers
300+
enable_jax_named_scopes: False
301+
302+
# Generation parameters
303+
prompt: "The person from the reference image follows the motion from the driving videos with natural body movement, stable identity, expressive face, cinematic framing, and realistic lighting."
304+
negative_prompt: "Bright tones, overexposed, static, blurred details, subtitles, style, works, paintings, images, static, overall gray, worst quality, low quality, JPEG compression residue, ugly, incomplete, extra fingers, poorly drawn hands, poorly drawn faces, deformed, disfigured, misshapen limbs, fused fingers, still picture, messy background, three legs, many people in the background, walking backwards"
305+
height: 720
306+
width: 1280
307+
num_frames: 121
308+
flow_shift: 5.0
309+
num_inference_steps: 30
310+
fps: 24
311+
save_final_checkpoint: False
312+
313+
# Wan Animate input overrides (used by generate_wan_animate.py).
314+
# Set these to local paths or HTTP(S) URLs. Sample assets should not live in the repo.
315+
mode: "animate"
316+
reference_image_path: ""
317+
pose_video_path: ""
318+
face_video_path: ""
319+
background_video_path: ""
320+
mask_video_path: ""
321+
segment_frame_length: 77
322+
prev_segment_conditioning_frames: 1
323+
motion_encode_batch_size: null
324+
# Values greater than 1.0 enable classifier-free guidance for WAnimate.
325+
animate_guidance_scale: 1.0
326+
327+
# Quantization plumbing is currently kept disabled for WAnimate.
328+
quantization: ''
329+
# Shard the range finding operation for quantization. By default this is set to number of slices.
330+
quantization_local_shard_count: -1
331+
compile_topology_num_slices: -1 # Number of target slices, set to a positive integer.
332+
use_qwix_quantization: False
333+
# Quantization calibration method used for weights, activations and bwd. Supported methods can be found in https://github.com/google/qwix/blob/dc2a0770351c740e5ab3cce7c0efe9f7beacce9e/qwix/qconfig.py#L70-L80
334+
weight_quantization_calibration_method: "absmax"
335+
act_quantization_calibration_method: "absmax"
336+
bwd_quantization_calibration_method: "absmax"
337+
qwix_module_path: ".*"
338+
339+
# Eval model on per eval_every steps. -1 means don't eval.
340+
eval_every: -1
341+
eval_data_dir: ""
342+
enable_generate_video_for_eval: False # This will increase the used TPU memory.
343+
eval_max_number_of_samples_in_bucket: 60 # The number of samples per bucket for evaluation. This is calculated by num_eval_samples / len(timesteps_list).
344+
345+
enable_ssim: False
346+
347+
use_batched_text_encoder: False

0 commit comments

Comments
 (0)