[Feature] support sp for hunyuan (#2163)
Signed-off-by: dengyunyang <584797741@qq.com> Signed-off-by: 汪志鹏 <wangzhipeng628@gmail.com> Co-authored-by: 汪志鹏 <wangzhipeng628@gmail.com>
This commit is contained in:
1 parent
c139ee4aed
commit
c0d90b64c6
6 files changed
+346
-27
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import functools
|
||||
import re
|
||||
import time
|
||||
from collections.abc import Callable
|
||||
from threading import Lock
|
||||
@@ -30,20 +31,31 @@ def profiler(name: str, func: Callable, instance: Any) -> Callable:
|
||||
logger.info(f"[DiffusionPipelineProfiler] {name} took {duration:.6f}s")
|
||||
# record the profiling data: duration of stages
|
||||
with instance._profiler_lock:
|
||||
instance._stage_durations[name] = duration
|
||||
instance._stage_durations[name] = instance._stage_durations.get(name, 0.0) + duration
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
def _parse_part(part: str) -> tuple[str, int | None]:
|
||||
"""Parse 'att[num]' into ('att', num)."""
|
||||
if m := re.compile(r"(\w+)\[(\d+)\]").fullmatch(part):
|
||||
return m.group(1), int(m.group(2))
|
||||
return part, None
|
||||
|
||||
|
||||
def _get_attribute_by_path(obj: Any, path: str) -> tuple[Any, str]:
|
||||
"""Traverse an object by dotted path and return (parent_obj, attribute_name)."""
|
||||
parts = path.split(".")
|
||||
current = obj
|
||||
|
||||
for part in parts[:-1]:
|
||||
current = getattr(current, part, None)
|
||||
attr, idx = _parse_part(part)
|
||||
|
||||
current = getattr(current, attr, None)
|
||||
if current is None:
|
||||
return None, None
|
||||
if idx is not None:
|
||||
current = current[idx]
|
||||
|
||||
return current, parts[-1]
|
||||
|
||||
|
||||
Reference in new issue
Block a user