create_file接口
本接口仅支持MindSpore框架。
接口功能
使用with调用create_file接口,用于创建文件,并返回对应的_WriteableFileWrapper实例。该实例提供write()、drop()和close()方法。
- write:向文件中写入数据。
write(self, data: bytes)
参数
是否必选
说明
取值要求
data
必选
需要写入的对象。
bytes对象。
- drop:删除文件。
drop(self)
- close:关闭文件。
接口格式
mindio_acp.create_file(path: str, mode: int = 0o600)
接口参数
参数 |
是否必选 |
说明 |
取值要求 |
---|---|---|---|
path |
必选 |
数据保存路径。 |
有效文件路径。 |
mode |
可选 |
文件创建权限。 |
[0o000, 0o777] |
使用样例
>>> x = torch.tensor([0, 1, 2, 3, 4]) >>> with mindio_acp.create_file('/mnt/dpc01/checkpoint/rank-0.pt') as f: ... write_result = f.write(x)
父主题: API接口参考