Skip to content

Commit 70cf529

Browse files
author
J石页
committed
NPU Adaption for Sanna
1 parent 3add6de commit 70cf529

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

examples/dreambooth/train_dreambooth_lora_sana.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ def parse_args(input_args=None):
605605
)
606606
parser.add_argument("--local_rank", type=int, default=-1, help="For distributed training: local_rank")
607607
parser.add_argument("--enable_vae_tiling", action="store_true", help="Enabla vae tiling in log validation")
608+
parser.add_argument("--enable_npu_flash_attention", action="store_true", help="Enabla Flash Attention for NPU")
608609

609610
if input_args is not None:
610611
args = parser.parse_args(input_args)
@@ -991,6 +992,13 @@ def main(args):
991992
# because Gemma2 is particularly suited for bfloat16.
992993
text_encoder.to(dtype=torch.bfloat16)
993994

995+
if args.enable_npu_flash_attention:
996+
if is_torch_npu_available():
997+
logger.info("npu flash attention enabled.")
998+
transformer.enable_npu_flash_attention()
999+
else:
1000+
raise ValueError("npu flash attention requires torch_npu extensions and is supported only on npu device ")
1001+
9941002
# Initialize a text encoding pipeline and keep it to CPU for now.
9951003
text_encoding_pipeline = SanaPipeline.from_pretrained(
9961004
args.pretrained_model_name_or_path,

0 commit comments

Comments
 (0)