Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
e9dd2b0
feat(npu): add Ascend platform abstraction and MindIE attention
Aug 13, 2026
a030fcb
feat(npu): enable Ulysses SP with CFG parallel on Ascend
Aug 13, 2026
8d1302c
feat(npu): fuse Qwen DiT addcmul, MindIE RoPE, and LN modulate
Aug 13, 2026
bfa1663
Add AscendLongContextAttention: NPU/MindIE long-context attention
Aug 13, 2026
7b8f81e
feat(npu): long-context attention, fused ops, unified platform abstra…
gaoyuanyuanqiqi Aug 18, 2026
6704256
feat(npu): extract AscendLongContextAttention to standalone file
Aug 21, 2026
dc3e080
feat(npu): add attention factory function for platform-aware creation
Aug 21, 2026
405e697
test(npu): add unit tests for attention factory
Aug 21, 2026
b49b54a
feat(npu): add unified platform ops interface for fused operators
Aug 21, 2026
2254061
test(npu): add unit tests for platform ops
Aug 21, 2026
7ca6b99
refactor(npu): replace NPU hardcoded branches with unified platform o…
Aug 21, 2026
6c4cc32
test(npu): add NPU multi-card parallel tests (4-card and 8-card Ulyss…
Aug 21, 2026
33cdd49
test(npu): add NPU single-card integration tests for all Qwen Image s…
Aug 21, 2026
2e5f17a
docs(npu): torch.compile FFN exploration - no benefit on current NPU …
Aug 22, 2026
050fb35
docs(npu): add NPU performance analysis report
Aug 22, 2026
cc717c9
docs(npu): add NPU adaptation technical documentation
Aug 22, 2026
aa567d4
perf(multicard): add GPU/NPU multi-card scaling profiling data
Aug 22, 2026
e5d744f
perf(multicard): verify CFG parallel P0 optimization (+102% on 8-card…
Aug 22, 2026
84acce6
bench: add PR#270 vs refactored same-methodology NPU comparison
Aug 22, 2026
a837164
fix(attention): add attn_type guard to factory dispatch and honor cau…
Aug 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,11 @@ dist/
CLAUDE.md
.claude/
.kiro/

# Performance benchmarks & results (internal use only)
benchmarks/
results/

# PR artifacts
PR_BODY.md
.pr272.diff
6 changes: 6 additions & 0 deletions diffsynth_engine/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ def parse_cli_args() -> Dict[str, Any]:
action="store_true",
help="Compile repeated transformer blocks with torch.compile",
)
optimization_group.add_argument(
"--compile-ffn",
action="store_true",
help="Compile only FFN (MLP) blocks with torch.compile (finer-grained than --use-torch-compile)",
)

# Parallelism configuration group
parallel_group = parser.add_argument_group("Parallelism Configuration")
Expand Down Expand Up @@ -184,6 +189,7 @@ def parse_cli_args() -> Dict[str, Any]:

# Optimization configuration
args_dict["use_torch_compile"] = args.use_torch_compile
args_dict["compile_ffn"] = args.compile_ffn

# Parallelism configuration
args_dict["parallelism"] = args.parallelism
Expand Down
13 changes: 12 additions & 1 deletion diffsynth_engine/configs/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from diffsynth_engine.layers.attention import AttentionType
from diffsynth_engine.registry import get_attn_backend
from diffsynth_engine.utils import logging
from diffsynth_engine.platforms import get_device_type, resolve_platform

logger = logging.get_logger(__name__)

Expand All @@ -27,7 +28,7 @@ class PipelineConfig:
model_dtype: torch.dtype = torch.bfloat16
text_encoder_dtype: torch.dtype = torch.bfloat16
vae_dtype: torch.dtype = torch.float32
device: str | torch.device = "cuda"
device: str | torch.device = "auto"

pipeline_class_name: str | None = None

Expand All @@ -42,6 +43,7 @@ class PipelineConfig:

# optimization
use_torch_compile: bool = False
compile_ffn: bool = False

# parallelism
parallelism: int = 1
Expand All @@ -62,6 +64,7 @@ def __post_init__(self):
self.attn_type = str(self.attn_type)
init_parallel_config(self)
validate_attn_config(self)
init_device_config(self)


def init_parallel_config(config: PipelineConfig):
Expand Down Expand Up @@ -109,3 +112,11 @@ def validate_attn_config(config: PipelineConfig):
if config.sp_ring_degree is not None and config.sp_ring_degree > 1:
if not attn_backend.supports_ring_attention():
raise ValueError(f"Attention backend {config.attn_type!r} does not support ring attention.")


def init_device_config(config: PipelineConfig):
if config.device is None or (isinstance(config.device, str) and config.device.lower() in ("auto", "")):
config.device = get_device_type()
return
# Validate that the explicit device type is registered (fail fast at construction).
resolve_platform(config.device)
31 changes: 18 additions & 13 deletions diffsynth_engine/distributed/parallel_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import torch
import torch.distributed
from torch.cuda import device_count, set_device

from diffsynth_engine.distributed.group_coordinator import (
GroupCoordinator,
Expand All @@ -22,7 +21,11 @@
)
from diffsynth_engine.utils import logging
from diffsynth_engine.utils.constants import IDLE_TIMEOUT_SEC
from diffsynth_engine.utils.platform import get_torch_distributed_backend
from diffsynth_engine.utils.platform import (
device_count,
get_torch_distributed_backend,
set_device,
)

logger = logging.get_logger(__name__)

Expand Down Expand Up @@ -425,28 +428,30 @@ def init_distributed_environment(
distributed_init_method,
backend,
)
# local_rank is not available in torch ProcessGroup,
# see https://github.com/pytorch/pytorch/issues/122816
if local_rank == -1:
# local rank not set, this usually happens in single-node
# setting, where we can use rank as local rank
if distributed_init_method == "env://":
local_rank = int(os.environ.get("LOCAL_RANK", "0"))
else:
local_rank = rank if rank >= 0 else 0

if not torch.distributed.is_initialized():
assert distributed_init_method is not None, (
"distributed_init_method must be provided when initializing distributed environment"
)
# Bind device before init_process_group (required by HCCL on Ascend).
set_device(local_rank % max(device_count(), 1))
# this backend is used for WORLD
torch.distributed.init_process_group(
backend=backend,
init_method=distributed_init_method,
world_size=world_size,
rank=rank,
)
set_device(torch.distributed.get_rank() % device_count())
# set the local rank
# local_rank is not available in torch ProcessGroup,
# see https://github.com/pytorch/pytorch/issues/122816
if local_rank == -1:
# local rank not set, this usually happens in single-node
# setting, where we can use rank as local rank
if distributed_init_method == "env://":
local_rank = int(os.environ.get("LOCAL_RANK", "0"))
else:
local_rank = rank
set_device(torch.distributed.get_rank() % max(device_count(), 1))
global _WORLD
if _WORLD is None:
ranks = list(range(torch.distributed.get_world_size()))
Expand Down
2 changes: 1 addition & 1 deletion diffsynth_engine/engine.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from typing import Any

import torch.multiprocessing as mp
from torch.cuda import set_device

from diffsynth_engine.configs import PipelineConfig
from diffsynth_engine.registry import (
get_pipeline_class,
get_pipeline_class_name,
)
from diffsynth_engine.utils import logging
from diffsynth_engine.utils.platform import set_device
from diffsynth_engine.utils.torch_profiler import TorchProfiler
from diffsynth_engine.worker import run_worker_loop

Expand Down
5 changes: 5 additions & 0 deletions diffsynth_engine/layers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from diffsynth_engine.layers.transformer_helper import RMSNorm

__all__ = [
"RMSNorm",
]
4 changes: 4 additions & 0 deletions diffsynth_engine/layers/attention/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from .backends.abstract import AttentionMetadata, AttentionType
from .factory import create_parallel_attention
from .layer import LocalAttention, USPAttention
from .ascend_long_context import AscendLongContextAttention

__all__ = [
"AttentionType",
"AttentionMetadata",
"LocalAttention",
"USPAttention",
"AscendLongContextAttention",
"create_parallel_attention",
]
Loading