diffsynth 2.1.12__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {diffsynth-2.1.12 → diffsynth-2.2.0}/PKG-INFO +1 -1
- diffsynth-2.2.0/diffsynth/core/attention/__init__.py +2 -0
- diffsynth-2.2.0/diffsynth/core/attention/attention.py +51 -0
- diffsynth-2.2.0/diffsynth/core/attention/common.py +27 -0
- diffsynth-2.2.0/diffsynth/core/attention/flash_attention.py +118 -0
- diffsynth-2.2.0/diffsynth/core/attention/flex_attention.py +28 -0
- diffsynth-2.2.0/diffsynth/core/attention/registry.py +48 -0
- diffsynth-2.2.0/diffsynth/core/attention/sage_attention.py +20 -0
- diffsynth-2.2.0/diffsynth/core/attention/torch_attention.py +82 -0
- diffsynth-2.2.0/diffsynth/core/attention/xformers_attention.py +22 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/data/operators.py +11 -5
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/data/unified_dataset.py +2 -1
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/gradient/gradient_checkpoint.py +5 -6
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/loader/config.py +2 -2
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/loader/model.py +12 -4
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/quant/backends/__init__.py +2 -0
- diffsynth-2.2.0/diffsynth/core/quant/backends/deep_gemm.py +618 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_h3_dit_vdn.py +1 -1
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/version.py +1 -1
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth.egg-info/PKG-INFO +1 -1
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth.egg-info/SOURCES.txt +8 -0
- diffsynth-2.1.12/diffsynth/core/attention/__init__.py +0 -1
- diffsynth-2.1.12/diffsynth/core/attention/attention.py +0 -255
- {diffsynth-2.1.12 → diffsynth-2.2.0}/LICENSE +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/README.md +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/configs/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/configs/model_configs.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/configs/vram_management_module_maps.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/data/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/device/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/device/npu_compatible_device.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/gradient/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/loader/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/loader/file.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/npu_patch/npu_fused_operator.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/offload_training/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/offload_training/manager.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/offload_training/memory_buffer.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/offload_training/offloader.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/quant/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/quant/backends/bitsandbytes.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/quant/backends/comfy_kitchen.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/quant/backends/entropack.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/quant/backends/torchao.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/quant/base.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/quant/config.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/vram/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/vram/disk_map.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/vram/initialization.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/core/vram/layers.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/diffusion/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/diffusion/base_pipeline.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/diffusion/ddim_scheduler.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/diffusion/dmd2.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/diffusion/flow_match.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/diffusion/logger.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/diffusion/loss.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/diffusion/parsers.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/diffusion/runner.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/diffusion/template.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/diffusion/training_module.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/aesthetic.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/base.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/bioclip.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/clip.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/fid.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/hpsv2.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/hpsv3.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/image_reward.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/lpips.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/pickscore.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/qwen_image_bench.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/unified_reward_2.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/metrics/unified_reward_edit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ace_step_conditioner.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ace_step_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ace_step_residual_fsq.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ace_step_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ace_step_tokenizer.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ace_step_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/aesthetic.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/anima_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/bioclip.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/boogu_image_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/clip.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/demucs.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/diffsynth_music_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/dinov3_image_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ernie_image_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ernie_image_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/fibo_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/fid.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux2_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux2_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux2_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux3_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux_controlnet.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux_infiniteyou.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux_ipadapter.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux_lora_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux_lora_patcher.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux_redux.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux_text_encoder_clip.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux_text_encoder_t5.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/flux_value_control.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/general_modules.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/hidream_common.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/hidream_o1_image_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/hpsv2.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/hpsv3.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ideogram4_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ideogram4_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ideogram4_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/image_reward.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/joyai_image_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/krea2_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/krea2_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/lingbot_video_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/longcat_video_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/lpips.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ltx25_diffusion_video_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ltx25_duration_head.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ltx25_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ltx2_audio_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ltx2_common.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ltx2_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ltx2_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ltx2_upsampler.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/ltx2_video_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_h3_audio_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_h3_controlnet.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_h3_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_h3_dit_comfy.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_h3_dit_vdn_fp8.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_h3_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_h3_video_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_music3_condition_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_music3_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_music3_rvq_depth_decoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_music3_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/minimax_music3_vocoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/model_loader.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/moss_image_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/moss_image_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/mova_audio_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/mova_audio_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/mova_dual_tower_bridge.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/nexus_gen.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/nexus_gen_ar_model.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/nexus_gen_projector.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/pickscore.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/qwen_image_21_controlnet.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/qwen_image_21_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/qwen_image_21_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/qwen_image_21_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/qwen_image_bench.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/qwen_image_controlnet.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/qwen_image_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/qwen_image_image2lora.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/qwen_image_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/qwen_image_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/qwen_video_edit_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/sd_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/sensenova_u1_common.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/sensenova_u1_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/siglip2_image_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/stable_diffusion_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/stable_diffusion_unet.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/stable_diffusion_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/stable_diffusion_xl_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/stable_diffusion_xl_unet.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/step1x_connector.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/step1x_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/unified_reward_2.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/unified_reward_edit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wan_animate_2_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wan_video_animate_adapter.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wan_video_camera_controller.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wan_video_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wan_video_dit_s2v.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wan_video_image_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wan_video_mot.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wan_video_motion_controller.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wan_video_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wan_video_vace.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wan_video_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wantodance.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/wav2vec.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/yue2_mot.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/yue2_tokenizer.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/yue2_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/z_image_controlnet.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/z_image_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/z_image_image2lora.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/models/z_image_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/ace_step.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/anima_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/boogu_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/diffsynth_music.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/ernie_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/fibo.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/flux2_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/flux3_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/flux_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/hidream_o1_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/ideogram4.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/joyai_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/krea2.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/lingbot_video.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/ltx2_audio_video.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/minimax_h3_audio_video.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/minimax_music3.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/moss_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/mova_audio_video.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/qwen_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/qwen_image_21.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/qwen_video_edit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/sensenova_u1_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/stable_diffusion.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/stable_diffusion_xl.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/wan_video.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/yue2.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/pipelines/z_image.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/controlnet/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/controlnet/annotator.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/controlnet/controlnet_input.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/data/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/data/audio.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/data/audio_video.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/data/media_io_ltx2.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/data/minimax_h3.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/demucs/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/dequantizer/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/lora/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/lora/flux.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/lora/flux_timestep.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/lora/general.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/lora/krea2.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/lora/merge.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/lora/minimax_h3.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/lora/reset_rank.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/lora/sdxl.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/music_tools/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/music_tools/click.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/music_tools/prosody.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/quant/serialization.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/ses/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/ses/ses.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ace_step_conditioner.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ace_step_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ace_step_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ace_step_tokenizer.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/anima_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/dino_v3.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ernie_image_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/flux2_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/flux3_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/flux_controlnet.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/flux_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/flux_infiniteyou.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/flux_ipadapter.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/flux_text_encoder_clip.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/flux_text_encoder_t5.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/flux_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ideogram4_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/image_metrics.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/krea2_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/krea2_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/lingbot_video_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ltx25_diffusion_video_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ltx25_duration_head.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ltx25_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ltx2_audio_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ltx2_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ltx2_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/ltx2_video_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/minimax_h3_audio_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/minimax_h3_controlnet.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/minimax_h3_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/minimax_h3_dit_vdn.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/minimax_h3_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/minimax_h3_video_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/minimax_music3_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/moss_image_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/nexus_gen.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/nexus_gen_projector.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/qwen_image_21_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/qwen_image_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/qwen_video_edit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/sdxl.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/sdxl_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/sdxl_text_encoder_2.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/sdxl_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/stable_diffusion_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/stable_diffusion_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/stable_diffusion_xl_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/step1x_connector.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/wan_video_animate_adapter.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/wan_video_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/wan_video_image_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/wan_video_mot.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/wan_video_vace.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/wan_video_vae.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/wans2v_audio_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/z_image_dit.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/state_dict_converters/z_image_text_encoder.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/tile/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/tile/tile_worker.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/xfuser/__init__.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth/utils/xfuser/xdit_context_parallel.py +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth.egg-info/dependency_links.txt +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth.egg-info/requires.txt +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/diffsynth.egg-info/top_level.txt +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/pyproject.toml +0 -0
- {diffsynth-2.1.12 → diffsynth-2.2.0}/setup.cfg +0 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from .registry import (
|
|
3
|
+
get_attention_implementation,
|
|
4
|
+
list_attention_implementations,
|
|
5
|
+
register_attention_implementation,
|
|
6
|
+
)
|
|
7
|
+
from .flash_attention import CUSTOMIZED_FA_KERNEL_AVAILABLE, FLASH_ATTN_4_AVAILABLE, FLASH_ATTN_3_AVAILABLE, FLASH_ATTN_2_AVAILABLE
|
|
8
|
+
from .sage_attention import SAGE_ATTN_AVAILABLE
|
|
9
|
+
from .xformers_attention import XFORMERS_AVAILABLE
|
|
10
|
+
from .torch_attention import torch_sdpa, torch_sdpa_sliding_window
|
|
11
|
+
from .flex_attention import flex_attention
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def initialize_attention_priority():
|
|
15
|
+
if os.environ.get('DIFFSYNTH_ATTENTION_IMPLEMENTATION') is not None:
|
|
16
|
+
return os.environ.get('DIFFSYNTH_ATTENTION_IMPLEMENTATION').strip().lower()
|
|
17
|
+
else:
|
|
18
|
+
for name in ["customized_fa_kernel", "flash_attention_4", "flash_attention_3", "flash_attention_2", "sage_attention", "xformers"]:
|
|
19
|
+
if name in list_attention_implementations():
|
|
20
|
+
return name
|
|
21
|
+
return "torch"
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
ATTENTION_IMPLEMENTATION = initialize_attention_priority()
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def attention_forward(q, k, v, q_pattern="b n s d", k_pattern="b n s d", v_pattern="b n s d", out_pattern="b n s d", dims=None, attn_mask=None, scale=None, is_causal=False, compatibility_mode=False, window_size=None, use_flex=False, score_mod=None):
|
|
28
|
+
if use_flex or score_mod is not None:
|
|
29
|
+
return flex_attention(q, k, v, q_pattern, k_pattern, v_pattern, out_pattern, dims, attn_mask=attn_mask, scale=scale, score_mod=score_mod)
|
|
30
|
+
|
|
31
|
+
if compatibility_mode:
|
|
32
|
+
return torch_sdpa(q, k, v, q_pattern, k_pattern, v_pattern, out_pattern, dims, attn_mask=attn_mask, scale=scale, is_causal=is_causal, window_size=window_size)
|
|
33
|
+
|
|
34
|
+
backend = get_attention_implementation(ATTENTION_IMPLEMENTATION)
|
|
35
|
+
|
|
36
|
+
if attn_mask is not None and not backend.supports_mask:
|
|
37
|
+
return torch_sdpa(q, k, v, q_pattern, k_pattern, v_pattern, out_pattern, dims, attn_mask=attn_mask, scale=scale, is_causal=is_causal)
|
|
38
|
+
if window_size is not None and not backend.supports_window:
|
|
39
|
+
assert is_causal == False and attn_mask is None
|
|
40
|
+
return torch_sdpa_sliding_window(q, k, v, window_size, q_pattern, k_pattern, v_pattern, out_pattern, dims, scale=scale)
|
|
41
|
+
if is_causal and not backend.supports_causal:
|
|
42
|
+
return torch_sdpa(q, k, v, q_pattern, k_pattern, v_pattern, out_pattern, dims, attn_mask=attn_mask, scale=scale, is_causal=is_causal)
|
|
43
|
+
|
|
44
|
+
kwargs = {"scale": scale}
|
|
45
|
+
if backend.supports_causal:
|
|
46
|
+
kwargs["is_causal"] = is_causal
|
|
47
|
+
if backend.supports_mask:
|
|
48
|
+
kwargs["attn_mask"] = attn_mask
|
|
49
|
+
if backend.supports_window:
|
|
50
|
+
kwargs["window_size"] = window_size
|
|
51
|
+
return backend.func(q, k, v, q_pattern, k_pattern, v_pattern, out_pattern, dims, **kwargs)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import inspect
|
|
2
|
+
|
|
3
|
+
import torch
|
|
4
|
+
from einops import rearrange
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
TORCH_SUPPORT_GQA = "enable_gqa" in inspect.signature(torch.nn.functional.scaled_dot_product_attention).parameters
|
|
8
|
+
except Exception:
|
|
9
|
+
TORCH_SUPPORT_GQA = False
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def rearrange_qkv(q: torch.Tensor, k: torch.Tensor, v: torch.Tensor, q_pattern="b n s d", k_pattern="b n s d", v_pattern="b n s d", required_in_pattern="b n s d", dims=None):
|
|
13
|
+
dims = {} if dims is None else dims
|
|
14
|
+
if q_pattern != required_in_pattern:
|
|
15
|
+
q = rearrange(q, f"{q_pattern} -> {required_in_pattern}", **dims)
|
|
16
|
+
if k_pattern != required_in_pattern:
|
|
17
|
+
k = rearrange(k, f"{k_pattern} -> {required_in_pattern}", **dims)
|
|
18
|
+
if v_pattern != required_in_pattern:
|
|
19
|
+
v = rearrange(v, f"{v_pattern} -> {required_in_pattern}", **dims)
|
|
20
|
+
return q, k, v
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def rearrange_out(out: torch.Tensor, out_pattern="b n s d", required_out_pattern="b n s d", dims=None):
|
|
24
|
+
dims = {} if dims is None else dims
|
|
25
|
+
if out_pattern != required_out_pattern:
|
|
26
|
+
out = rearrange(out, f"{required_out_pattern} -> {out_pattern}", **dims)
|
|
27
|
+
return out
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import os
|
|
2
|
+
|
|
3
|
+
from .common import rearrange_qkv, rearrange_out
|
|
4
|
+
from .registry import register_attention_implementation
|
|
5
|
+
|
|
6
|
+
if os.environ.get("DIFFSYNTH_FLASH_ATTN_KERNEL_REPO_ID") is not None:
|
|
7
|
+
try:
|
|
8
|
+
from kernels import get_kernel
|
|
9
|
+
kernel_module = get_kernel(os.environ.get("DIFFSYNTH_FLASH_ATTN_KERNEL_REPO_ID"), version=int(os.environ.get("DIFFSYNTH_FLASH_ATTN_KERNEL_VERSION")))
|
|
10
|
+
customized_flash_attn_func = kernel_module.flash_attn_func
|
|
11
|
+
CUSTOMIZED_FA_KERNEL_AVAILABLE = True
|
|
12
|
+
except Exception:
|
|
13
|
+
CUSTOMIZED_FA_KERNEL_AVAILABLE = False
|
|
14
|
+
else:
|
|
15
|
+
CUSTOMIZED_FA_KERNEL_AVAILABLE = False
|
|
16
|
+
|
|
17
|
+
try:
|
|
18
|
+
from flash_attn.cute import flash_attn_func as flash_attn_func_cute
|
|
19
|
+
FLASH_ATTN_4_AVAILABLE = True
|
|
20
|
+
except Exception:
|
|
21
|
+
FLASH_ATTN_4_AVAILABLE = False
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
from flash_attn_3 import flash_attn_interface
|
|
25
|
+
FLASH_ATTN_3_AVAILABLE = True
|
|
26
|
+
except Exception:
|
|
27
|
+
FLASH_ATTN_3_AVAILABLE = False
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
import flash_attn
|
|
31
|
+
FLASH_ATTN_2_AVAILABLE = hasattr(flash_attn, "flash_attn_func")
|
|
32
|
+
except Exception:
|
|
33
|
+
FLASH_ATTN_2_AVAILABLE = False
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _require(flag, name):
|
|
37
|
+
if not flag:
|
|
38
|
+
raise RuntimeError(f"{name} is not available.")
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def flash_attention_4(q, k, v, q_pattern="b n s d", k_pattern="b n s d", v_pattern="b n s d", out_pattern="b n s d", dims=None, scale=None, is_causal=False, window_size=None):
|
|
42
|
+
_require(FLASH_ATTN_4_AVAILABLE, "FlashAttention-4")
|
|
43
|
+
required_in_pattern, required_out_pattern = "b s n d", "b s n d"
|
|
44
|
+
q, k, v = rearrange_qkv(q, k, v, q_pattern, k_pattern, v_pattern, required_in_pattern, dims)
|
|
45
|
+
window_size = (window_size, window_size) if window_size is not None else (-1, -1)
|
|
46
|
+
out = flash_attn_func_cute(q, k, v, softmax_scale=scale, causal=is_causal, window_size=window_size)
|
|
47
|
+
if isinstance(out, tuple):
|
|
48
|
+
out = out[0]
|
|
49
|
+
out = rearrange_out(out, out_pattern, required_out_pattern, dims)
|
|
50
|
+
return out
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def flash_attention_3(q, k, v, q_pattern="b n s d", k_pattern="b n s d", v_pattern="b n s d", out_pattern="b n s d", dims=None, scale=None, is_causal=False, window_size=None):
|
|
54
|
+
_require(FLASH_ATTN_3_AVAILABLE, "FlashAttention-3")
|
|
55
|
+
required_in_pattern, required_out_pattern = "b s n d", "b s n d"
|
|
56
|
+
q, k, v = rearrange_qkv(q, k, v, q_pattern, k_pattern, v_pattern, required_in_pattern, dims)
|
|
57
|
+
window_size = (window_size, window_size) if window_size is not None else (-1, -1)
|
|
58
|
+
out = flash_attn_interface.flash_attn_func(q, k, v, softmax_scale=scale, causal=is_causal, window_size=window_size)
|
|
59
|
+
if isinstance(out, tuple):
|
|
60
|
+
out = out[0]
|
|
61
|
+
out = rearrange_out(out, out_pattern, required_out_pattern, dims)
|
|
62
|
+
return out
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def flash_attention_2(q, k, v, q_pattern="b n s d", k_pattern="b n s d", v_pattern="b n s d", out_pattern="b n s d", dims=None, scale=None, is_causal=False, window_size=None):
|
|
66
|
+
_require(FLASH_ATTN_2_AVAILABLE, "FlashAttention-2")
|
|
67
|
+
required_in_pattern, required_out_pattern = "b s n d", "b s n d"
|
|
68
|
+
q, k, v = rearrange_qkv(q, k, v, q_pattern, k_pattern, v_pattern, required_in_pattern, dims)
|
|
69
|
+
window_size = (window_size, window_size) if window_size is not None else (-1, -1)
|
|
70
|
+
out = flash_attn.flash_attn_func(q, k, v, softmax_scale=scale, causal=is_causal, window_size=window_size)
|
|
71
|
+
out = rearrange_out(out, out_pattern, required_out_pattern, dims)
|
|
72
|
+
return out
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def flash_attention_customized_kernel(q, k, v, q_pattern="b n s d", k_pattern="b n s d", v_pattern="b n s d", out_pattern="b n s d", dims=None, scale=None, is_causal=False, window_size=None):
|
|
76
|
+
_require(CUSTOMIZED_FA_KERNEL_AVAILABLE, "customized FlashAttention kernel")
|
|
77
|
+
required_in_pattern, required_out_pattern = "b s n d", "b s n d"
|
|
78
|
+
q, k, v = rearrange_qkv(q, k, v, q_pattern, k_pattern, v_pattern, required_in_pattern, dims)
|
|
79
|
+
window_size = (window_size, window_size) if window_size is not None else (-1, -1)
|
|
80
|
+
out = customized_flash_attn_func(q, k, v, softmax_scale=scale, causal=is_causal, window_size=window_size)
|
|
81
|
+
if isinstance(out, tuple):
|
|
82
|
+
out = out[0]
|
|
83
|
+
out = rearrange_out(out, out_pattern, required_out_pattern, dims)
|
|
84
|
+
return out
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
if CUSTOMIZED_FA_KERNEL_AVAILABLE:
|
|
88
|
+
register_attention_implementation(
|
|
89
|
+
"customized_fa_kernel",
|
|
90
|
+
flash_attention_customized_kernel,
|
|
91
|
+
supports_causal=True,
|
|
92
|
+
supports_window=True,
|
|
93
|
+
supports_gqa=True,
|
|
94
|
+
)
|
|
95
|
+
if FLASH_ATTN_4_AVAILABLE:
|
|
96
|
+
register_attention_implementation(
|
|
97
|
+
"flash_attention_4",
|
|
98
|
+
flash_attention_4,
|
|
99
|
+
supports_causal=True,
|
|
100
|
+
supports_window=True,
|
|
101
|
+
supports_gqa=True,
|
|
102
|
+
)
|
|
103
|
+
if FLASH_ATTN_3_AVAILABLE:
|
|
104
|
+
register_attention_implementation(
|
|
105
|
+
"flash_attention_3",
|
|
106
|
+
flash_attention_3,
|
|
107
|
+
supports_causal=True,
|
|
108
|
+
supports_window=True,
|
|
109
|
+
supports_gqa=True,
|
|
110
|
+
)
|
|
111
|
+
if FLASH_ATTN_2_AVAILABLE:
|
|
112
|
+
register_attention_implementation(
|
|
113
|
+
"flash_attention_2",
|
|
114
|
+
flash_attention_2,
|
|
115
|
+
supports_causal=True,
|
|
116
|
+
supports_window=True,
|
|
117
|
+
supports_gqa=True,
|
|
118
|
+
)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
|
|
3
|
+
from .common import rearrange_qkv, rearrange_out
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
from torch.nn.attention.flex_attention import flex_attention as _flex_attention_func
|
|
7
|
+
FLEX_ATTN_AVAILABLE = True
|
|
8
|
+
except Exception:
|
|
9
|
+
FLEX_ATTN_AVAILABLE = False
|
|
10
|
+
|
|
11
|
+
# Compile flex attention lazily
|
|
12
|
+
_compiled_flex_attention_func = None
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def get_flex_attention_func():
|
|
16
|
+
global _compiled_flex_attention_func
|
|
17
|
+
if _compiled_flex_attention_func is None:
|
|
18
|
+
_compiled_flex_attention_func = torch.compile(_flex_attention_func)
|
|
19
|
+
return _compiled_flex_attention_func
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def flex_attention(q, k, v, q_pattern="b n s d", k_pattern="b n s d", v_pattern="b n s d", out_pattern="b n s d", dims=None, attn_mask=None, scale=None, score_mod=None):
|
|
23
|
+
assert FLEX_ATTN_AVAILABLE, "Flex Attention is not available. Please upgrade torch to 2.5.0 or later."
|
|
24
|
+
required_in_pattern, required_out_pattern = "b n s d", "b n s d"
|
|
25
|
+
q, k, v = rearrange_qkv(q, k, v, q_pattern, k_pattern, v_pattern, required_in_pattern, dims)
|
|
26
|
+
out = get_flex_attention_func()(query=q, key=k, value=v, block_mask=attn_mask, scale=scale, score_mod=score_mod)
|
|
27
|
+
out = rearrange_out(out, out_pattern, required_out_pattern, dims)
|
|
28
|
+
return out
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Callable, Optional
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@dataclass(frozen=True)
|
|
6
|
+
class AttentionBackend:
|
|
7
|
+
func: Callable
|
|
8
|
+
supports_causal: bool = False
|
|
9
|
+
supports_window: bool = False
|
|
10
|
+
supports_mask: bool = False
|
|
11
|
+
supports_gqa: bool = False
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
_ATTENTION_BACKENDS = {}
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def register_attention_implementation(
|
|
18
|
+
name: str,
|
|
19
|
+
func: Optional[Callable] = None,
|
|
20
|
+
supports_causal: bool = False,
|
|
21
|
+
supports_window: bool = False,
|
|
22
|
+
supports_mask: bool = False,
|
|
23
|
+
supports_gqa: bool = False,
|
|
24
|
+
):
|
|
25
|
+
key = name.strip().lower()
|
|
26
|
+
_ATTENTION_BACKENDS[key] = AttentionBackend(
|
|
27
|
+
func=func,
|
|
28
|
+
supports_causal=supports_causal,
|
|
29
|
+
supports_window=supports_window,
|
|
30
|
+
supports_mask=supports_mask,
|
|
31
|
+
supports_gqa=supports_gqa,
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def get_attention_implementation(name: str) -> AttentionBackend:
|
|
36
|
+
key = name.strip().lower()
|
|
37
|
+
if key not in _ATTENTION_BACKENDS:
|
|
38
|
+
available = ", ".join(list_attention_implementations()) or "none"
|
|
39
|
+
raise ValueError(
|
|
40
|
+
f"Unknown attention implementation: {name!r}. "
|
|
41
|
+
f"Available implementations: {available}. "
|
|
42
|
+
f"Please check the environment variable `DIFFSYNTH_ATTENTION_IMPLEMENTATION`."
|
|
43
|
+
)
|
|
44
|
+
return _ATTENTION_BACKENDS[key]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def list_attention_implementations():
|
|
48
|
+
return sorted(_ATTENTION_BACKENDS)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from .common import rearrange_qkv, rearrange_out
|
|
2
|
+
from .registry import register_attention_implementation
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
from sageattention import sageattn
|
|
6
|
+
SAGE_ATTN_AVAILABLE = True
|
|
7
|
+
except Exception:
|
|
8
|
+
SAGE_ATTN_AVAILABLE = False
|
|
9
|
+
|
|
10
|
+
def sage_attention(q, k, v, q_pattern="b n s d", k_pattern="b n s d", v_pattern="b n s d", out_pattern="b n s d", dims=None, scale=None):
|
|
11
|
+
if not SAGE_ATTN_AVAILABLE:
|
|
12
|
+
raise RuntimeError("SageAttention is not available.")
|
|
13
|
+
required_in_pattern, required_out_pattern = "b n s d", "b n s d"
|
|
14
|
+
q, k, v = rearrange_qkv(q, k, v, q_pattern, k_pattern, v_pattern, required_in_pattern, dims)
|
|
15
|
+
out = sageattn(q, k, v, sm_scale=scale)
|
|
16
|
+
out = rearrange_out(out, out_pattern, required_out_pattern, dims)
|
|
17
|
+
return out
|
|
18
|
+
|
|
19
|
+
if SAGE_ATTN_AVAILABLE:
|
|
20
|
+
register_attention_implementation("sage_attention", sage_attention)
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import torch
|
|
2
|
+
from einops import repeat
|
|
3
|
+
|
|
4
|
+
from .common import TORCH_SUPPORT_GQA, rearrange_qkv, rearrange_out
|
|
5
|
+
from .registry import register_attention_implementation
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def torch_sdpa(q: torch.Tensor, k: torch.Tensor, v: torch.Tensor, q_pattern="b n s d", k_pattern="b n s d", v_pattern="b n s d", out_pattern="b n s d", dims=None, attn_mask=None, scale=None, is_causal=False, window_size=None):
|
|
9
|
+
if window_size is not None:
|
|
10
|
+
if is_causal or attn_mask is not None:
|
|
11
|
+
raise ValueError("Sliding window attention does not support `is_causal=True` or `attn_mask`.")
|
|
12
|
+
return torch_sdpa_sliding_window(q, k, v, window_size, q_pattern, k_pattern, v_pattern, out_pattern, dims, scale=scale)
|
|
13
|
+
|
|
14
|
+
required_in_pattern, required_out_pattern = "b n s d", "b n s d"
|
|
15
|
+
q, k, v = rearrange_qkv(q, k, v, q_pattern, k_pattern, v_pattern, required_in_pattern, dims)
|
|
16
|
+
if q.shape[1] != k.shape[1] or q.shape[1] != v.shape[1]:
|
|
17
|
+
# Grouped Query Attention
|
|
18
|
+
if TORCH_SUPPORT_GQA:
|
|
19
|
+
out = torch.nn.functional.scaled_dot_product_attention(q, k, v, attn_mask, scale=scale, is_causal=is_causal, enable_gqa=True)
|
|
20
|
+
else:
|
|
21
|
+
# In low-version torch, `enable_gqa` is not supported.
|
|
22
|
+
k = repeat(k, "b n s d -> b (n m) s d", m=q.shape[1]//k.shape[1])
|
|
23
|
+
v = repeat(v, "b n s d -> b (n m) s d", m=q.shape[1]//v.shape[1])
|
|
24
|
+
out = torch.nn.functional.scaled_dot_product_attention(q, k, v, attn_mask, scale=scale, is_causal=is_causal)
|
|
25
|
+
else:
|
|
26
|
+
out = torch.nn.functional.scaled_dot_product_attention(q, k, v, attn_mask, scale=scale, is_causal=is_causal)
|
|
27
|
+
out = rearrange_out(out, out_pattern, required_out_pattern, dims)
|
|
28
|
+
return out
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def torch_sdpa_sliding_window(q: torch.Tensor, k: torch.Tensor, v: torch.Tensor, sliding_window: int, q_pattern="b n s d", k_pattern="b n s d", v_pattern="b n s d", out_pattern="b n s d", dims=None, scale=None):
|
|
32
|
+
required_in_pattern, required_out_pattern = "b n s d", "b n s d"
|
|
33
|
+
q, k, v = rearrange_qkv(q, k, v, q_pattern, k_pattern, v_pattern, required_in_pattern, dims)
|
|
34
|
+
|
|
35
|
+
B, N, S, D = q.shape
|
|
36
|
+
W = sliding_window
|
|
37
|
+
chunk_size = W
|
|
38
|
+
num_chunks = (S + chunk_size - 1) // chunk_size
|
|
39
|
+
|
|
40
|
+
output = torch.empty_like(q)
|
|
41
|
+
dtype = q.dtype
|
|
42
|
+
device = q.device
|
|
43
|
+
min_val = torch.finfo(dtype).min
|
|
44
|
+
|
|
45
|
+
for i in range(num_chunks):
|
|
46
|
+
q_start = i * chunk_size
|
|
47
|
+
q_end = min(q_start + chunk_size, S)
|
|
48
|
+
actual_chunk_size = q_end - q_start
|
|
49
|
+
|
|
50
|
+
kv_start = max(0, q_start - W)
|
|
51
|
+
kv_end = min(S, q_end + W)
|
|
52
|
+
|
|
53
|
+
q_chunk = q[:, :, q_start:q_end, :]
|
|
54
|
+
k_chunk = k[:, :, kv_start:kv_end, :]
|
|
55
|
+
v_chunk = v[:, :, kv_start:kv_end, :]
|
|
56
|
+
|
|
57
|
+
q_indices = torch.arange(q_start, q_end, device=device)
|
|
58
|
+
k_indices = torch.arange(kv_start, kv_end, device=device)
|
|
59
|
+
diff = q_indices.unsqueeze(1) - k_indices.unsqueeze(0)
|
|
60
|
+
valid = diff.abs() <= W
|
|
61
|
+
|
|
62
|
+
local_mask = torch.zeros(actual_chunk_size, kv_end - kv_start, dtype=dtype, device=device)
|
|
63
|
+
local_mask.masked_fill_(~valid, min_val)
|
|
64
|
+
local_mask = local_mask.unsqueeze(0).unsqueeze(0)
|
|
65
|
+
|
|
66
|
+
out_chunk = torch_sdpa(
|
|
67
|
+
q_chunk, k_chunk, v_chunk, attn_mask=local_mask, scale=scale
|
|
68
|
+
)
|
|
69
|
+
output[:, :, q_start:q_end, :] = out_chunk
|
|
70
|
+
|
|
71
|
+
output = rearrange_out(output, out_pattern, required_out_pattern, dims)
|
|
72
|
+
return output
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
register_attention_implementation(
|
|
76
|
+
"torch",
|
|
77
|
+
torch_sdpa,
|
|
78
|
+
supports_window=True,
|
|
79
|
+
supports_causal=True,
|
|
80
|
+
supports_mask=True,
|
|
81
|
+
supports_gqa=True,
|
|
82
|
+
)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from .common import rearrange_qkv, rearrange_out
|
|
2
|
+
from .registry import register_attention_implementation
|
|
3
|
+
|
|
4
|
+
try:
|
|
5
|
+
import xformers.ops as xops
|
|
6
|
+
XFORMERS_AVAILABLE = True
|
|
7
|
+
except Exception:
|
|
8
|
+
XFORMERS_AVAILABLE = False
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def xformers_attention(q, k, v, q_pattern="b n s d", k_pattern="b n s d", v_pattern="b n s d", out_pattern="b n s d", dims=None, scale=None):
|
|
12
|
+
if not XFORMERS_AVAILABLE:
|
|
13
|
+
raise RuntimeError("xformers is not available.")
|
|
14
|
+
required_in_pattern, required_out_pattern = "b s n d", "b s n d"
|
|
15
|
+
q, k, v = rearrange_qkv(q, k, v, q_pattern, k_pattern, v_pattern, required_in_pattern, dims)
|
|
16
|
+
out = xops.memory_efficient_attention(q, k, v, scale=scale)
|
|
17
|
+
out = rearrange_out(out, out_pattern, required_out_pattern, dims)
|
|
18
|
+
return out
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
if XFORMERS_AVAILABLE:
|
|
22
|
+
register_attention_implementation("xformers", xformers_attention)
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import math, warnings, time
|
|
2
|
-
import torch,
|
|
3
|
-
import imageio.v3 as iio
|
|
2
|
+
import torch, os
|
|
4
3
|
import urllib.request
|
|
5
4
|
from io import BytesIO
|
|
6
5
|
from PIL import Image
|
|
@@ -100,16 +99,20 @@ class ImageCropAndResize(DataProcessingOperator):
|
|
|
100
99
|
self.max_pixels = max_pixels
|
|
101
100
|
self.height_division_factor = height_division_factor
|
|
102
101
|
self.width_division_factor = width_division_factor
|
|
102
|
+
import torchvision
|
|
103
|
+
self.resize = torchvision.transforms.functional.resize
|
|
104
|
+
self.center_crop = torchvision.transforms.functional.center_crop
|
|
105
|
+
self.interpolation_mode = torchvision.transforms.InterpolationMode.BILINEAR
|
|
103
106
|
|
|
104
107
|
def crop_and_resize(self, image, target_height, target_width):
|
|
105
108
|
width, height = image.size
|
|
106
109
|
scale = max(target_width / width, target_height / height)
|
|
107
|
-
image =
|
|
110
|
+
image = self.resize(
|
|
108
111
|
image,
|
|
109
112
|
(round(height*scale), round(width*scale)),
|
|
110
|
-
interpolation=
|
|
113
|
+
interpolation=self.interpolation_mode
|
|
111
114
|
)
|
|
112
|
-
image =
|
|
115
|
+
image = self.center_crop(image, (target_height, target_width))
|
|
113
116
|
return image
|
|
114
117
|
|
|
115
118
|
def get_height_width(self, image):
|
|
@@ -143,6 +146,7 @@ class FrameSamplerByRateMixin:
|
|
|
143
146
|
self.fix_frame_rate = fix_frame_rate
|
|
144
147
|
|
|
145
148
|
def get_reader(self, data: str):
|
|
149
|
+
import imageio
|
|
146
150
|
return imageio.get_reader(data)
|
|
147
151
|
|
|
148
152
|
def get_available_num_frames(self, reader):
|
|
@@ -213,6 +217,7 @@ class LoadGIF(DataProcessingOperator):
|
|
|
213
217
|
|
|
214
218
|
def get_num_frames(self, path):
|
|
215
219
|
num_frames = self.num_frames
|
|
220
|
+
import imageio.v3 as iio
|
|
216
221
|
images = iio.imread(path, mode="RGB")
|
|
217
222
|
if len(images) < num_frames:
|
|
218
223
|
num_frames = len(images)
|
|
@@ -223,6 +228,7 @@ class LoadGIF(DataProcessingOperator):
|
|
|
223
228
|
def __call__(self, data: str):
|
|
224
229
|
num_frames = self.get_num_frames(data)
|
|
225
230
|
frames = []
|
|
231
|
+
import imageio.v3 as iio
|
|
226
232
|
images = iio.imread(data, mode="RGB")
|
|
227
233
|
for img in images:
|
|
228
234
|
frame = Image.fromarray(img)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from .operators import *
|
|
2
|
-
import torch, json,
|
|
2
|
+
import torch, json, os
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
class UnifiedDataset(torch.utils.data.Dataset):
|
|
@@ -84,6 +84,7 @@ class UnifiedDataset(torch.utils.data.Dataset):
|
|
|
84
84
|
metadata.append(json.loads(line.strip()))
|
|
85
85
|
self.data = metadata
|
|
86
86
|
else:
|
|
87
|
+
import pandas
|
|
87
88
|
metadata = pandas.read_csv(metadata_path)
|
|
88
89
|
self.data = [metadata.iloc[i].to_dict() for i in range(len(metadata))]
|
|
89
90
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import torch
|
|
2
|
+
import sys
|
|
2
3
|
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
_HAS_DEEPSPEED = True
|
|
7
|
-
except ModuleNotFoundError:
|
|
8
|
-
_HAS_DEEPSPEED = False
|
|
5
|
+
def get_deepspeed():
|
|
6
|
+
return sys.modules.get("deepspeed")
|
|
9
7
|
|
|
10
8
|
|
|
11
9
|
def create_custom_forward(module):
|
|
@@ -36,7 +34,8 @@ def gradient_checkpoint_forward(
|
|
|
36
34
|
*args,
|
|
37
35
|
**kwargs,
|
|
38
36
|
):
|
|
39
|
-
if use_gradient_checkpointing
|
|
37
|
+
deepspeed = get_deepspeed() if use_gradient_checkpointing else None
|
|
38
|
+
if use_gradient_checkpointing and deepspeed is not None and deepspeed.checkpointing.is_configured():
|
|
40
39
|
kwarg_keys = tuple(kwargs)
|
|
41
40
|
all_args = args + tuple(kwargs.values())
|
|
42
41
|
if not judge_args_requires_grad(*all_args):
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import torch, glob, os, sys
|
|
2
2
|
from typing import Optional, Union, Dict
|
|
3
3
|
from dataclasses import dataclass
|
|
4
|
-
from modelscope import snapshot_download
|
|
5
|
-
from huggingface_hub import snapshot_download as hf_snapshot_download
|
|
6
4
|
from typing import Optional
|
|
7
5
|
from ..quant import QuantizeConfig, MixedQuantizeConfig
|
|
8
6
|
|
|
@@ -98,6 +96,7 @@ class ModelConfig:
|
|
|
98
96
|
downloaded_files = glob.glob(origin_file_pattern, root_dir=os.path.join(self.local_model_path, self.model_id))
|
|
99
97
|
download_source = self.parse_download_source()
|
|
100
98
|
if download_source.lower() == "modelscope":
|
|
99
|
+
from modelscope import snapshot_download
|
|
101
100
|
snapshot_download(
|
|
102
101
|
self.model_id,
|
|
103
102
|
local_dir=os.path.join(self.local_model_path, self.model_id),
|
|
@@ -106,6 +105,7 @@ class ModelConfig:
|
|
|
106
105
|
local_files_only=False
|
|
107
106
|
)
|
|
108
107
|
elif download_source.lower() == "huggingface":
|
|
108
|
+
from huggingface_hub import snapshot_download as hf_snapshot_download
|
|
109
109
|
hf_snapshot_download(
|
|
110
110
|
self.model_id,
|
|
111
111
|
local_dir=os.path.join(self.local_model_path, self.model_id),
|
|
@@ -3,14 +3,22 @@ from ..vram.disk_map import DiskMap
|
|
|
3
3
|
from ..vram.layers import enable_vram_management
|
|
4
4
|
from .file import load_state_dict, load_metadata_from_safetensors
|
|
5
5
|
import torch
|
|
6
|
-
|
|
7
|
-
from
|
|
8
|
-
|
|
6
|
+
import sys
|
|
7
|
+
from contextlib import ExitStack
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def is_deepspeed_zero3_enabled():
|
|
11
|
+
if "transformers" not in sys.modules:
|
|
12
|
+
return False
|
|
13
|
+
from transformers.integrations import is_deepspeed_zero3_enabled as _is_deepspeed_zero3_enabled
|
|
14
|
+
return _is_deepspeed_zero3_enabled()
|
|
9
15
|
|
|
10
16
|
|
|
11
17
|
def load_model(model_class, path, config=None, torch_dtype=torch.bfloat16, device="cpu", state_dict_converter=None, use_disk_map=False, module_map=None, vram_config=None, vram_limit=None, state_dict=None, quantize=None):
|
|
12
18
|
config = {} if config is None else config
|
|
13
|
-
with
|
|
19
|
+
with ExitStack() as stack:
|
|
20
|
+
for init_context in get_init_context(torch_dtype=torch_dtype, device=device):
|
|
21
|
+
stack.enter_context(init_context)
|
|
14
22
|
model = model_class(**config)
|
|
15
23
|
# What is `module_map`?
|
|
16
24
|
# This is a module mapping table for VRAM management.
|