其他
OneFlow v0.4.0 正式发布
with flow.scope.placement("gpu", "0:0-3", (2, 2)):
x = flow.hierarchical_parallel_cast(
x, parallel_distribution=["B", "S(1)"]
)
with flow.scope.placement("gpu", "0:0-3", (4,)):
x = flow.hierarchical_parallel_cast(
x, parallel_distribution=["S(0)"]
)
with flow.experimental.scope.config(
pipeline_stage_id_hint=dist_util.get_layer_stage(layer_idx)
):
...
func_cfg = flow.FunctionConfig()
...
func_cfg.train.num_gradient_accumulation_steps(args.num_accumulation_steps)
@flow.global_function(..., function_config=func_cfg)
func_cfg = flow.FunctionConfig()
...
func_cfg.optimizer_placement_optimization_mode(mode) # mode = "non_distributed" or "distributed_split"
@flow.global_function(..., function_config=func_cfg)
with flow.experimental.scope.config(
checkpointing=True
):
import oneflow.experimental as flow
flow.enable_eager_execution() # 启用 eager
flow.nn.Conv2d <-> torch.nn.Conv2d
flow.nn.BatchNorm2d <-> torch.nn.BatchNorm2d
flow.nn.ReLU <-> torch.nn.ReLU
flow.nn.MaxPool2d <-> torch.nn.MaxPool2d
flow.nn.AvgPool2d <-> torch.nn.AvgPool2d
flow.nn.Linear <-> torch.nn.Linear
flow.nn.CrossEntropyLoss <-> torch.nn.CrossEntropyLoss
flow.nn.Sequential <-> torch.nn.Sequential
flow.nn.Module.to <-> torch.nn.Module.to
flow.nn.Module.state_dict <-> torch.nn.Module.state_dict
flow.nn.Module.load_state_dict <-> torch.nn.Module.load_state_dict
flow.save <-> torch.save
flow.load <-> torch.load
flow.Tensor <-> torch.Tensor
flow.tensor <-> torch.tensor
flow.tensor.to <-> torch.tensor.to
flow.tensor.numpy <-> torch.tensor.numpy
flow.tensor 加减乘除 <-> torch.tensor 加减乘除
flow.tensor.flatten <-> torch.tensor.flatten
flow.tensor.softmax <-> torch.tensor.softmax
flow.optim.SGD <-> torch.optim.SGD
基于上述模块已经可以轻松搭建常用网络,如:ResNet、BERT、MobileNetV3 等。后续版本将对齐/支持更多接口,届时可将大多数基于 PyTorch 搭建的网络,轻松切换到 OneFlow。
快速上手例子 lenet:
https://github.com/Oneflow-Inc/models/blob/main/quick_start_demo_lenet/lenet.py
新接口文档链接:
https://oneflow.readthedocs.io/en/master/experimental.html
对齐 torch vision 的 resnet50 示例代码:
https://github.com/Oneflow-Inc/models/tree/main/resnet50
接下来的版本会增加更多对齐 PyTorch 的接口
experimental 下对齐的接口在 0.6.0 版本更新时会被移动到 OneFlow 的命名空间下,届时会完全对齐 PyTorch,OneFlow 0.6.0 会将 eager 作为默认的执行方式
eager 模式目前只支持单 GPU 运行,在 0.5.0 会支持多 GPU 运行
4.下集预告
在下一个版本的 OneFlow 中,将包含更全面的 PyTorch 兼容,包括更丰富的接口支持以及更多 GPU 支持。同时,下个版本的 OneFlow 也将支持动静图转换功能。敬请期待。