项目文件夹

文件
wehub-resource-sync 593b94c120
pytest / Unit Tests (push) Has been cancelled
pytest / Integration (integration_tests_a) (push) Has been cancelled
pytest / Integration (integration_tests_b) (push) Has been cancelled
pytest / Integration (integration_tests_c) (push) Has been cancelled
pytest / Integration (integration_tests_d) (push) Has been cancelled
pytest / Integration (integration_tests_e) (push) Has been cancelled
pytest / Integration (integration_tests_f) (push) Has been cancelled
pytest / Integration (integration_tests_g) (push) Has been cancelled
pytest / Integration (integration_tests_h) (push) Has been cancelled
pytest / Integration (integration_tests_i) (push) Has been cancelled
pytest / Integration (integration_tests_j) (push) Has been cancelled
pytest / Distributed (distributed_a) (push) Has been cancelled
pytest / Distributed (distributed_b) (push) Has been cancelled
pytest / Distributed (distributed_c) (push) Has been cancelled
pytest / Distributed (distributed_d) (push) Has been cancelled
pytest / Distributed (distributed_e) (push) Has been cancelled
pytest / Distributed (distributed_f) (push) Has been cancelled
pytest / Minimal Install (push) Has been cancelled
pytest / Event File (push) Has been cancelled
pytest (slow) / py-slow (push) Has been cancelled
Publish JSON Schema / publish-schema (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:49:20 +08:00

55 行
1.3 KiB
Python

from typing import Any
from ludwig.distributed.base import DistributedStrategy, LocalStrategy
def load_local():
return LocalStrategy
def load_accelerate():
from ludwig.distributed.accelerate import AccelerateStrategy
return AccelerateStrategy
STRATEGIES = {
"accelerate": load_accelerate,
"local": load_local,
# Legacy aliases for backward compatibility
"ddp": load_accelerate,
"fsdp": load_accelerate,
"deepspeed": load_accelerate,
}
_current_strategy: DistributedStrategy = None
def init_dist_strategy(strategy: str | dict[str, Any], **kwargs) -> DistributedStrategy:
global _current_strategy
if isinstance(strategy, dict):
dtype = strategy.pop("type", None)
obj = get_dist_strategy(dtype)(**strategy)
else:
obj = get_dist_strategy(strategy)(**kwargs)
_current_strategy = obj
return obj
def get_current_dist_strategy() -> DistributedStrategy:
if _current_strategy is None:
raise RuntimeError("Distributed strategy not initialized")
return _current_strategy
def get_dist_strategy(strategy: str | dict[str, Any]) -> type[DistributedStrategy]:
name = strategy
if isinstance(strategy, dict):
name = strategy["type"]
return STRATEGIES[name]()
def get_default_strategy_name() -> str:
return "accelerate"