@@ -282,18 +282,19 @@ OSS connector for AI/ML supports [PyTorch distributed checkpoints(DCP)](https://
282282``` py
283283import torchvision
284284import torch.distributed.checkpoint as DCP
285- from osstorchconnector import OssFileSystem
285+ from osstorchconnector import OssDCPFileSystem
286286import torch
287287
288288ENDPOINT = " http://oss-cn-beijing-internal.aliyuncs.com"
289+ REGION = " cn-beijing"
289290CONFIG_PATH = " /etc/oss-connector/config.json"
290291CRED_PATH = " /root/.alibabacloud/credentials"
291292OSS_URI = " oss://ossconnectorbucket/dcp-checkpoint-resnet18"
292293
293294model = torchvision.models.resnet18()
294295
295296# write to OSS
296- fs = OssFileSystem (endpoint = ENDPOINT , cred_path = CRED_PATH , config_path = CONFIG_PATH )
297+ fs = OssDCPFileSystem (endpoint = ENDPOINT , cred_path = CRED_PATH , config_path = CONFIG_PATH , region = REGION )
297298oss_storage_writer = fs.writer(OSS_URI )
298299# DCP.save or DCP.async_save
299300checkpoint_future = DCP .async_save(
@@ -324,11 +325,12 @@ import torch
324325from osstorchconnector import OssSafetensor
325326
326327ENDPOINT = " http://oss-cn-beijing-internal.aliyuncs.com"
328+ REGION = " cn-beijing"
327329CONFIG_PATH = " /etc/oss-connector/config.json"
328330CRED_PATH = " /root/.alibabacloud/credentials"
329331OSS_URI = " oss://ossconnectorbucket/safetensors/model.safetensors"
330332
331- sfts = OssSafetensor(endpoint = HTTPS_ENDPOINT , cred_path = CRED_PATH , config_path = CONFIG_PATH )
333+ sfts = OssSafetensor(endpoint = ENDPOINT , cred_path = CRED_PATH , config_path = CONFIG_PATH , region = REGION )
332334
333335# save tensors to safetensor file on OSS
334336tensors = {" embedding" : torch.rand((512 , 1024 )), " attention" : torch.rand((256 , 256 ))}
@@ -344,4 +346,4 @@ with sfts.safe_open(OSS_URI, device ="cpu") as f:
344346 for key in f.keys(): # read tensors by keys
345347 tensor = f.get_tensor(key)
346348
347- ```
349+ ```
0 commit comments