Skip to content

Commit 3bfdc92

Browse files
committed
Add lora for WAN models
1 parent 6907953 commit 3bfdc92

7 files changed

Lines changed: 1420 additions & 0 deletions

File tree

Lines changed: 334 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,334 @@
1+
# Copyright 2023 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.1-T2V-14B-Diffusers'
31+
model_name: wan2.1
32+
33+
# Overrides the transformer from pretrained_model_name_or_path
34+
wan_transformer_pretrained_model_name_or_path: ''
35+
36+
unet_checkpoint: ''
37+
revision: ''
38+
# This will convert the weights to this dtype.
39+
# When running inference on TPUv5e, use weights_dtype: 'bfloat16'
40+
weights_dtype: 'bfloat16'
41+
# This sets the layer's dtype in the model. Ex: nn.Dense(dtype=activations_dtype)
42+
activations_dtype: 'bfloat16'
43+
44+
# Replicates vae across devices instead of using the model's sharding annotations for sharding.
45+
replicate_vae: False
46+
47+
# matmul and conv precision from https://jax.readthedocs.io/en/latest/jax.lax.html#jax.lax.Precision
48+
# Options are "DEFAULT", "HIGH", "HIGHEST"
49+
# fp32 activations and fp32 weights with HIGHEST will provide the best precision
50+
# at the cost of time.
51+
precision: "DEFAULT"
52+
# Use jax.lax.scan for transformer layers
53+
scan_layers: False
54+
55+
# if False state is not jitted and instead replicate is called. This is good for debugging on single host
56+
# It must be True for multi-host.
57+
jit_initializers: True
58+
59+
# Set true to load weights from pytorch
60+
from_pt: True
61+
split_head_dim: True
62+
attention: 'flash' # Supported attention: dot_product, flash, cudnn_flash_te, ring
63+
flash_min_seq_length: 4096
64+
dropout: 0.1
65+
66+
#flash_block_sizes: {
67+
# "block_q" : 1024,
68+
# "block_kv_compute" : 256,
69+
# "block_kv" : 1024,
70+
# "block_q_dkv" : 1024,
71+
# "block_kv_dkv" : 1024,
72+
# "block_kv_dkv_compute" : 256,
73+
# "block_q_dq" : 1024,
74+
# "block_kv_dq" : 1024
75+
#}
76+
# Use on v6e
77+
flash_block_sizes: {
78+
"block_q" : 3024,
79+
"block_kv_compute" : 1024,
80+
"block_kv" : 2048,
81+
"block_q_dkv" : 3024,
82+
"block_kv_dkv" : 2048,
83+
"block_kv_dkv_compute" : 2048,
84+
"block_q_dq" : 3024,
85+
"block_kv_dq" : 2048,
86+
"use_fused_bwd_kernel": False,
87+
}
88+
# GroupNorm groups
89+
norm_num_groups: 32
90+
91+
# train text_encoder - Currently not supported for SDXL
92+
train_text_encoder: False
93+
text_encoder_learning_rate: 4.25e-6
94+
95+
# https://arxiv.org/pdf/2305.08891.pdf
96+
snr_gamma: -1.0
97+
98+
timestep_bias: {
99+
# a value of later will increase the frequence of the model's final training steps.
100+
# none, earlier, later, range
101+
strategy: "none",
102+
# multiplier for bias, a value of 2.0 will double the weight of the bias, 0.5 will halve it.
103+
multiplier: 1.0,
104+
# when using strategy=range, the beginning (inclusive) timestep to bias.
105+
begin: 0,
106+
# when using strategy=range, the final step (inclusive) to bias.
107+
end: 1000,
108+
# portion of timesteps to bias.
109+
# 0.5 will bias one half of the timesteps. Value of strategy determines
110+
# whether the biased portions are in the earlier or later timesteps.
111+
portion: 0.25
112+
}
113+
114+
# Override parameters from checkpoints's scheduler.
115+
diffusion_scheduler_config: {
116+
_class_name: 'FlaxEulerDiscreteScheduler',
117+
prediction_type: 'epsilon',
118+
rescale_zero_terminal_snr: False,
119+
timestep_spacing: 'trailing'
120+
}
121+
122+
# Output directory
123+
# Create a GCS bucket, e.g. my-maxtext-outputs and set this to "gs://my-maxtext-outputs/"
124+
base_output_directory: ""
125+
126+
# Hardware
127+
hardware: 'tpu' # Supported hardware types are 'tpu', 'gpu'
128+
skip_jax_distributed_system: False
129+
130+
# Parallelism
131+
mesh_axes: ['data', 'fsdp', 'tensor']
132+
133+
# batch : batch dimension of data and activations
134+
# hidden :
135+
# embed : attention qkv dense layer hidden dim named as embed
136+
# heads : attention head dim = num_heads * head_dim
137+
# length : attention sequence length
138+
# temb_in : dense.shape[0] of resnet dense before conv
139+
# out_c : dense.shape[1] of resnet dense before conv
140+
# out_channels : conv.shape[-1] activation
141+
# keep_1 : conv.shape[0] weight
142+
# keep_2 : conv.shape[1] weight
143+
# conv_in : conv.shape[2] weight
144+
# conv_out : conv.shape[-1] weight
145+
logical_axis_rules: [
146+
['batch', 'data'],
147+
['activation_batch', 'data'],
148+
['activation_length', 'fsdp'],
149+
150+
['activation_heads', 'tensor'],
151+
['mlp','tensor'],
152+
['embed','fsdp'],
153+
['heads', 'tensor'],
154+
['norm', 'tensor'],
155+
['conv_batch', ['data','fsdp']],
156+
['out_channels', 'tensor'],
157+
['conv_out', 'fsdp'],
158+
]
159+
data_sharding: [['data', 'fsdp', 'tensor']]
160+
161+
# One axis for each parallelism type may hold a placeholder (-1)
162+
# value to auto-shard based on available slices and devices.
163+
# By default, product of the DCN axes should equal number of slices
164+
# and product of the ICI axes should equal number of devices per slice.
165+
dcn_data_parallelism: 1 # recommended DCN axis to be auto-sharded
166+
dcn_fsdp_parallelism: -1
167+
dcn_tensor_parallelism: 1
168+
ici_data_parallelism: 1
169+
ici_fsdp_parallelism: -1 # recommended ICI axis to be auto-sharded
170+
ici_tensor_parallelism: 1
171+
172+
allow_split_physical_axes: True
173+
174+
# Dataset
175+
# Replace with dataset path or train_data_dir. One has to be set.
176+
dataset_name: 'diffusers/pokemon-gpt4-captions'
177+
train_split: 'train'
178+
dataset_type: 'tfrecord'
179+
cache_latents_text_encoder_outputs: True
180+
# cache_latents_text_encoder_outputs only apply to dataset_type="tf",
181+
# only apply to small dataset that fits in memory
182+
# prepare image latents and text encoder outputs
183+
# Reduce memory consumption and reduce step time during training
184+
# transformed dataset is saved at dataset_save_location
185+
dataset_save_location: ''
186+
load_tfrecord_cached: True
187+
train_data_dir: ''
188+
dataset_config_name: ''
189+
jax_cache_dir: ''
190+
hf_data_dir: ''
191+
hf_train_files: ''
192+
hf_access_token: ''
193+
image_column: 'image'
194+
caption_column: 'text'
195+
resolution: 1024
196+
center_crop: False
197+
random_flip: False
198+
# If cache_latents_text_encoder_outputs is True
199+
# the num_proc is set to 1
200+
tokenize_captions_num_proc: 4
201+
transform_images_num_proc: 4
202+
reuse_example_batch: False
203+
enable_data_shuffling: True
204+
205+
# Defines the type of gradient checkpoint to enable.
206+
# NONE - means no gradient checkpoint
207+
# FULL - means full gradient checkpoint, whenever possible (minimum memory usage)
208+
# MATMUL_WITHOUT_BATCH - means gradient checkpoint for every linear/matmul operation,
209+
# except for ones that involve batch dimension - that means that all attention and projection
210+
# layers will have gradient checkpoint, but not the backward with respect to the parameters.
211+
# OFFLOAD_MATMUL_WITHOUT_BATCH - same as MATMUL_WITHOUT_BATCH but offload instead of recomputing.
212+
# CUSTOM - set names to offload and save.
213+
remat_policy: "NONE"
214+
# For CUSTOM policy set below, current annotations are for: attn_output, query_proj, key_proj, value_proj
215+
# xq_out, xk_out, ffn_activation
216+
names_which_can_be_saved: []
217+
names_which_can_be_offloaded: []
218+
219+
# checkpoint every number of samples, -1 means don't checkpoint.
220+
checkpoint_every: -1
221+
checkpoint_dir: ""
222+
# enables one replica to read the ckpt then broadcast to the rest
223+
enable_single_replica_ckpt_restoring: False
224+
225+
# Training loop
226+
learning_rate: 1.e-5
227+
scale_lr: False
228+
max_train_samples: -1
229+
# max_train_steps takes priority over num_train_epochs.
230+
max_train_steps: 1500
231+
num_train_epochs: 1
232+
seed: 0
233+
output_dir: 'sdxl-model-finetuned'
234+
per_device_batch_size: 1.0
235+
# If global_batch_size % jax.device_count is not 0, use FSDP sharding.
236+
global_batch_size: 0
237+
238+
# For creating tfrecords from dataset
239+
tfrecords_dir: ''
240+
no_records_per_shard: 0
241+
enable_eval_timesteps: False
242+
timesteps_list: [125, 250, 375, 500, 625, 750, 875]
243+
num_eval_samples: 420
244+
245+
warmup_steps_fraction: 0.1
246+
learning_rate_schedule_steps: -1 # By default the length of the schedule is set to the number of steps.
247+
save_optimizer: False
248+
249+
# However you may choose a longer schedule (learning_rate_schedule_steps > steps), in which case the training will end before
250+
# dropping fully down. Or you may choose a shorter schedule, where the unspecified steps will have a learning rate of 0.
251+
252+
# AdamW optimizer parameters
253+
adam_b1: 0.9 # Exponential decay rate to track the first moment of past gradients.
254+
adam_b2: 0.999 # Exponential decay rate to track the second moment of past gradients.
255+
adam_eps: 1.e-8 # A small constant applied to denominator outside of the square root.
256+
adam_weight_decay: 0 # AdamW Weight decay
257+
max_grad_norm: 1.0
258+
259+
enable_profiler: False
260+
# Skip first n steps for profiling, to omit things like compilation and to give
261+
# the iteration time a chance to stabilize.
262+
skip_first_n_steps_for_profiler: 5
263+
profiler_steps: 10
264+
265+
# Enable JAX named scopes for detailed profiling and debugging
266+
# When enabled, adds named scopes around key operations in transformer and attention layers
267+
enable_jax_named_scopes: False
268+
269+
# Generation parameters
270+
prompt: "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."
271+
prompt_2: "A cat and a dog baking a cake together in a kitchen. The cat is carefully measuring flour, while the dog is stirring the batter with a wooden spoon. The kitchen is cozy, with sunlight streaming through the window."
272+
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"
273+
do_classifier_free_guidance: True
274+
height: 720
275+
width: 1280
276+
num_frames: 81
277+
guidance_scale: 5.0
278+
flow_shift: 3.0
279+
280+
# Based on 3.4. in https://arxiv.org/pdf/2305.08891.pdf
281+
guidance_rescale: 0.0
282+
num_inference_steps: 30
283+
fps: 16
284+
save_final_checkpoint: False
285+
286+
# SDXL Lightning parameters
287+
lightning_from_pt: True
288+
# Empty or "ByteDance/SDXL-Lightning" to enable lightning.
289+
lightning_repo: ""
290+
# Empty or "sdxl_lightning_4step_unet.safetensors" to enable lightning.
291+
lightning_ckpt: ""
292+
293+
# LoRA parameters
294+
lora_rank: 64
295+
# Values are lists to support multiple LoRA loading during inference in the future.
296+
lora_config: {
297+
lora_model_name_or_path: ["lightx2v/Wan2.1-Distill-Loras"],
298+
weight_name: ["wan2.1_t2v_14b_lora_rank64_lightx2v_4step.safetensors"],
299+
adapter_name: ["wan21-distill-lora"],
300+
scale: [1.0],
301+
from_pt: []
302+
}
303+
# Ex with values:
304+
# lora_config : {
305+
# lora_model_name_or_path: ["ByteDance/Hyper-SD"],
306+
# weight_name: ["Hyper-SDXL-2steps-lora.safetensors"],
307+
# adapter_name: ["hyper-sdxl"],
308+
# scale: [0.7],
309+
# from_pt: [True]
310+
# }
311+
312+
enable_mllog: False
313+
314+
#controlnet
315+
controlnet_model_name_or_path: 'diffusers/controlnet-canny-sdxl-1.0'
316+
controlnet_from_pt: True
317+
controlnet_conditioning_scale: 0.5
318+
controlnet_image: 'https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Google_%22G%22_logo.svg/1024px-Google_%22G%22_logo.svg.png'
319+
quantization: ''
320+
# Shard the range finding operation for quantization. By default this is set to number of slices.
321+
quantization_local_shard_count: -1
322+
compile_topology_num_slices: -1 # Number of target slices, set to a positive integer.
323+
use_qwix_quantization: False # Whether to use qwix for quantization. If set to True, the transformer of WAN will be quantized using qwix.
324+
# Quantization calibration method used for weights and activations. Supported methods can be found in https://github.com/google/qwix/blob/dc2a0770351c740e5ab3cce7c0efe9f7beacce9e/qwix/qconfig.py#L70-L80
325+
quantization_calibration_method: "absmax"
326+
qwix_module_path: ".*"
327+
328+
# Eval model on per eval_every steps. -1 means don't eval.
329+
eval_every: -1
330+
eval_data_dir: ""
331+
enable_generate_video_for_eval: False # This will increase the used TPU memory.
332+
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).
333+
334+
enable_ssim: False

0 commit comments

Comments
 (0)