Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions diffsynth/core/loader/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def load_state_dict(file_path, torch_dtype=None, device="cpu"):


def load_state_dict_from_safetensors(file_path, torch_dtype=None, device="cpu"):
import torch.distributed as dist
from diffsynth.core.device.npu_compatible_device import get_device_name, IS_NPU_AVAILABLE, IS_CUDA_AVAILABLE
if dist.is_available() and dist.is_initialized() and (IS_CUDA_AVAILABLE or IS_NPU_AVAILABLE):
device = get_device_name()
state_dict = {}
with safe_open(file_path, framework="pt", device=str(device)) as f:
for k in f.keys():
Expand Down
4 changes: 4 additions & 0 deletions diffsynth/core/vram/disk_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def get_slice(self, name):
class DiskMap:

def __init__(self, path, device, torch_dtype=None, state_dict_converter=None, buffer_size=10**9):
import torch.distributed as dist
from diffsynth.core.device.npu_compatible_device import get_device_name, IS_NPU_AVAILABLE, IS_CUDA_AVAILABLE
if dist.is_available() and dist.is_initialized() and (IS_CUDA_AVAILABLE or IS_NPU_AVAILABLE):
device = get_device_name()
self.path = path if isinstance(path, list) else [path]
self.device = device
self.torch_dtype = torch_dtype
Expand Down