Version 1.0.0
Version 1.0.0
OneFlow v1.0.0 release note
OneFlow v1.0.0 came out, welcome to install the new version for a better experience.
- Highlights
- New Features
- Improvements
- Changes and Fixes
- Performance
Highlights
This version update includes 447 commits and the following highlights:
-
Released a new interface
compile_from_torch. This interface, while sharing the parameter memory, converts a PyTorch Module instance into a OneFlow Module instance. It supports direct Eager execution or conversion into a static graph nn.Graph, further accelerating the process using MLIR compilation. This interface is rapidly evolving and currently supports dynamic shape compilation, validated across typical models such as ResNet50, Faster RCNN, and Stable Diffusion. -
Made a series of optimizations and refactoring to Eager execution runtime, including unification of system memory pools, integration with CUDA native interfaces, optimization of instruction scheduling mechanisms, introduction of an instruction fusion mechanism, optimization of Autograd graph construction speed, optimization of Op inference process, and decoupling of Instruction and Stream, etc.
-
The static graph distributed physical execution plan supports separate compilation functionality, allowing each process to independently compile its required execution plan, eliminating linear growth of compilation time with GPU scale.
-
Addition of a series of functional automatic differentiation related interface supports, including jvp, vjp, hvp, vhp, jacobian, and hessian.
-
Addition of the Insight module, supporting visualization of kernel invocation, execution time, speed, and other related information within the embedded point intervals.
-
Updates to LiBai (the open-source toolbox for large-scale model training), with native support for fine-tuning and distributed inference of Llama2 and ChatGLM2, supporting full finetune, adapter finetune, lora finetune. lm-eval-harness can be used for language model evaluation and validation.
-
Upgrade of OneFlow Serving functionality, adding support for OneFlow Python backend and OneFlow Lite backend, in addition to the existing support for OneFlow Cpp backend.
New Features
1. compile_from_torch
The compile_from_torch interface, while sharing the parameter memory, converts a PyTorch Module instance into a OneFlow Module instance. It supports direct Eager execution or conversion into a static graph nn.Graph, further accelerating the process using MLIR compilation. (https://github.com/Oneflow-Inc/oneflow/pull/10404, https://github.com/Oneflow-Inc/oneflow/pull/10408, https://github.com/Oneflow-Inc/oneflow/pull/9984, https://github.com/Oneflow-Inc/oneflow/pull/9754)
Interface Signature and Parameter Introduction:
compile_from_torch(torch_module: torch.nn.Module, \*, use_graph=True, options={})
* torch_module: The Torch Module instance to be converted.
* use_graph: Indicates whether to transform into a static graph nn.Graph and utilize MLIR compilation acceleration. The default is True.
* options:
* size: When using static graph nn.Graph, the hash value of the graph corresponding to the input shape will be calculated and cached. Size indicates the maximum capacity of the static graph cache. When exceeding the maximum capacity, the graph will be cleared based on the LRU strategy. The default value is 9.
* dynamic: For the first input with a dynamic shape, the graph will be fully compiled. For subsequent inputs with different shapes, if dynamic is True, shared graph will be used for compilation acceleration; if dynamic is False, the compilation will be performed each time. The default is True.
* debug: Debug mode and log level settings. -1 disables debug mode, 0 outputs warnings and static graph construction information, 1 additionally outputs graph construction information for each sub-module, 2 additionally outputs progress for each operator, 3 provides more detailed operator information. The default value is -1.
Example of Usage:
import torch
from torchvision import models
import oneflow
from oneflow.framework.infer_compiler import compile_from_torch
DEVICE = torch.device("cuda")
WEIGHT = models.ResNet50_Weights.DEFAULT
model = models.resnet50(weights=WEIGHT).to(DEVICE)
compile_model = compile_from_torch(model, options={"dynamic": True})
2. Separated Compilation
The static graph distributed physical execution plan supports separate compilation , allowing each process to independently compile its required execution plan, thereby preventing linear growth of compilation time with GPU scale. The separate compilation feature supports 3D hybrid parallel (data parallelism + model parallelism + pipeline parallelism) scenarios and can be used together with LiBai (the open-source large-scale model training toolbox). To enable this feature, use the command: export ONEFLOW_ENABLE_LAZY_SEPARATE_COMPILE=1. (https://github.com/Oneflow-Inc/oneflow/pull/9920, https://github.com/Oneflow-Inc/oneflow/pull/10140, https://github.com/Oneflow-Inc/oneflow/pull/10141, https://github.com/Oneflow-Inc/oneflow/pull/10124, https://github.com/Oneflow-Inc/oneflow/pull/10102)
Below are the test results on a 128-card A100-PCIE-40GB device with LiBai on the GPT2 model:
| Parallelism | Separated Compilation Enabled | Execution Plan Compilation Time | | ------------ | ----------------------------------- | ------------------------------------ | | Data Parallelism (DP128 MP1 PP1) | No | Over 20 minutes | | Data Parallelism (DP128 MP1 PP1) | Yes | 108.21 s | | 3D Parallelism (DP4 MP4 PP8) | No | 445.16 s | | 3D Parallelism (DP4 MP4 PP8) | Yes | 82.88 s |
3. Functional Automatic Differentiation Interfaces
A series of functional automatic differentiation-related interfaces have been introduced, including jvp, vjp, hvp, vhp, jacobian, and hessian. (https://github.com/Oneflow-Inc/oneflow/pull/10412, https://github.com/Oneflow-Inc/oneflow/pull/10428)
Example of Usage:
import oneflow as flow
# jacobian example
def exp_reducer(x):
return x.exp().sum(dim=1)
input = flow.rand(2, 2)
jac_rslt = flow.autograd.functional.jacobian(exp_reducer, input)
# vhp example
def pow_reducer(x):
return x.pow(3).sum()
input = flow.rand(2, 2)
v = flow.ones(2, 2)
vhp_rslt = flow.autograd.functional.vhp(pow_reducer, input, v)
4. Insight Module
Introduced a new Insight module, enabling the visualization of kernel invocation, execution time, speed, and other related information within the embedded point intervals. (https://github.com/Oneflow-Inc/oneflow/pull/10370)
Usage:
- Step 1: Set embedded point intervals in the code using the OneFlow Profiler module.
- Step 2: Run the code and use NVIDIA Nsight Systems to generate a .sqlite file.
- Step 3: Use the OneFlow Insight module to generate a .json file.
- Step 4: Open the .json file in the browser at chrome://tracing/ or edge://tracing/ to obtain the visualization interface.
For more detailed information, please refer to: https://github.com/Oneflow-Inc/oneflow/tree/master/python/oneflow/utils/insight#usage
5. LiBai Version Update
-
LiBai (the open-source toolbox for large-scale model training) has been upgraded to version v0.3.0. It now natively supports finetuning and distributed inference of large language models Llama2 and ChatGLM2. It supports full full finetune, adapter finetune, lora finetune. lm-eval-harness can be used for language model evaluation and validation.
-
The distributed training and inference support for ChatGLM and Llama2 are as follows:
| Models | 2D (tp+pp) Inference | 3D Parallel Training |
|---|---|---|
| ChatGLM | ✔ | ✔ |
| Llama2 | ✔ | ✔ |
Example of Usage:
# full finetune
bash tools/train.sh projects/Llama/train_net.py projects/Llama/configs/llama_sft.py 8
# adapter finetune
bash tools/train.sh projects/Llama/adapter/train_net.py projects/Llama/adapter/adapter_sft.py 8
# inference
bash tools/infer.sh projects/Llama/pipeline.py 8
# eval
python projects/Llama/utils/eval_adapter.py
6. Other New Features
-
Added FFT-related operators. (https://github.com/Oneflow-Inc/oneflow/pull/10027)
-
Added
zetaoperator. (https://github.com/Oneflow-Inc/oneflow/pull/10189) -
Added
tril_operator. (https://github.com/Oneflow-Inc/oneflow/pull/9996) -
Added
cloneoperator. (https://github.com/Oneflow-Inc/oneflow/pull/9800) -
Added
fracandfrac_operator. (https://github.com/Oneflow-Inc/oneflow/pull/9979) -
Added
exp2operator. (https://github.com/Oneflow-Inc/oneflow/pull/9958) -
Added
rreluoperator. (https://github.com/Oneflow-Inc/oneflow/pull/9736) -
Added
lgammabackward operator. (https://github.com/Oneflow-Inc/oneflow/pull/10177) -
Added
digammaoperator. (https://github.com/Oneflow-Inc/oneflow/pull/10066) -
Added
trigammaoperator. (https://github.com/Oneflow-Inc/oneflow/pull/10117) -
Added
bitwise_notoperator. (https://github.com/Oneflow-Inc/oneflow/pull/9859) -
Added
squared_reluoperator. (https://github.com/Oneflow-Inc/oneflow/pull/10316) -
Added
skip_rms_normoperator. (https://github.com/Oneflow-Inc/oneflow/pull/10036) -
Added
multi_tensor_amp_grad_scalerrelated operators. (https://github.com/Oneflow-Inc/oneflow/pull/10071) -
Added
bitwise_and,bitwise_or,bitwise_xoroperators. (https://github.com/Oneflow-Inc/oneflow/pull/9842) -
Added
fused_attention_concat_past_key_valueoperator. (https://github.com/Oneflow-Inc/oneflow/pull/9963) -
Added
fused_multi_head_attention_inference_v2operator. (https://github.com/Oneflow-Inc/oneflow/pull/9933) -
Added
fused_codegeex_qkv_reshapeoperator. (https://github.com/Oneflow-Inc/oneflow/pull/9927) -
Added
fused_apply_rotary_emboperator. (https://github.com/Oneflow-Inc/oneflow/pull/9914) -
Added
skip_layer_normoperator. (https://github.com/Oneflow-Inc/oneflow/pull/9906) -
Added
groupwise_dequantize, operators. (https://github.com/Oneflow-Inc/oneflow/pull/9900)
Improvements
1. Eager Runtime Optimization and Refactoring
A series of optimizations and refactoring has been implemented for the Eager runtime, including:
-
Unified system memory pool to manage memory resources across all allocators on the same device. (https://github.com/Oneflow-Inc/oneflow/pull/8591)
-
Integration with CUDA native interfaces to accelerate kernel launches.(https://github.com/Oneflow-Inc/oneflow/pull/8571)
-
Optimization of instruction scheduling mechanism to reduce system overhead.(https://github.com/Oneflow-Inc/oneflow/pull/8796)
-
Introduction of instruction fusion mechanism to accelerate instruction dispatch. (https://github.com/Oneflow-Inc/oneflow/pull/7399)
-
Speed improvement in Autograd graph construction. (https://github.com/Oneflow-Inc/oneflow/pull/8606)
-
Optimization of op deduction process to accelerate kernel execution. (https://github.com/Oneflow-Inc/oneflow/pull/8672, https://github.com/Oneflow-Inc/oneflow/pull/8619, https://github.com/Oneflow-Inc/oneflow/pull/8662)
-
Consolidation of redundant concepts within the eager runtime, decoupling Instruction and Stream. (https://github.com/Oneflow-Inc/oneflow/pull/8583, https://github.com/Oneflow-Inc/oneflow/pull/8590, https://github.com/Oneflow-Inc/oneflow/pull/7607)
Users can configure the Eager runtime using various environment variables:
| Environment Variable | Meaning | Default Value | | -------------------- | ------- | ------------- | | ONEFLOW_VM_COMPUTE_ON_WORKER_THREAD | Whether to perform computation on worker threads | true | | ONEFLOW_VM_MULTI_THREAD | Whether to use multi-threaded collaboration for Eager computation | true | | ONEFLOW_VM_ENABLE_STREAM_WAIT | Whether to use stream_wait mechanism for dependencies between multiple streams | true | | ONEFLOW_VM_ENABLE_SCHEDULE_YIELD | Whether to use yield mechanism to reduce scheduler thread's busy wait | true | | ONEFLOW_EAGER_ENABLE_LOCAL_INFER_CACHE | Whether to cache operator output metadata during computation | true | | ONEFLOW_VM_WORKER_THREAD_LIMIT | Number of worker threads | 16 | | ONEFLOW_VM_PENDING_HANDLE_WINDOW_SIZE | Maximum size for fusing vm instructions | 10 | | ONEFLOW_VM_BLOCKING_DEBUG_INSTRUCTIONS_DISPLAY_LIMIT | Number of unprocessed instructions to be printed when vm execution times out | 1000 |
2. Upgrade of OneFlow Serving Features
OneFlow Serving features have been upgraded to support additional backends, including OneFlow Python backend and OneFlow Lite backend, in addition to the existing support for the OneFlow Cpp backend.
- The OneFlow Cpp backend enables deployment in a Python-independent environment to achieve the highest performance.
- The OneFlow Lite backend enables deployment on edge devices.
- The OneFlow Python backend facilitates the deployment of complex models with minimal migration cost.
For usage instructions, refer to: https://github.com/Oneflow-Inc/serving/blob/main/README.md
3. Other Functionality Improvements
-
Optimized certain code implementations to accommodate CUDA 12.x. (https://github.com/Oneflow-Inc/oneflow/pull/10367)
-
Optimized the glu operator implementation to support bias-less inputs.(https://github.com/Oneflow-Inc/oneflow/pull/9874)
-
Optimized pooling operator implementation to support the channels_last parameter. (https://github.com/Oneflow-Inc/oneflow/pull/10242)
-
Optimized the flip operator implementation to address memory access inefficiencies when dim = -1. (https://github.com/Oneflow-Inc/oneflow/pull/10310)
-
Optimized the bincount operator implementation for accelerated performance. (https://github.com/Oneflow-Inc/oneflow/pull/10308)
-
Optimized the index_add operator implementation by dispatching varied logic based on index length to enhance performance for smaller indices.(https://github.com/Oneflow-Inc/oneflow/pull/9751)
-
Optimized the topk operator implementation to boost performance when batch size equals 1. (https://github.com/Oneflow-Inc/oneflow/pull/10009)
-
Optimized implementations of operators such as conv and arange to facilitate CUDA graph usage. (https://github.com/Oneflow-Inc/oneflow/pull/9761)
-
Optimized the upsample operator implementation to include input/output size validation.(https://github.com/Oneflow-Inc/oneflow/pull/9737)
-
Optimized the grouped_matmul_bias operator implementation by introducing tensor parallelism sbp derivation rules. (https://github.com/Oneflow-Inc/oneflow/pull/9934)
-
Optimized the reshape operator implementation with added nd sbp derivation rules. (https://github.com/Oneflow-Inc/oneflow/pull/9858)
-
Optimized error messages and completed test cases for mask_fill and in_top_k operators. (https://github.com/Oneflow-Inc/oneflow/pull/10062)
-
Optimized the higher-order differentiation rules for the tanh operator to optimize performance under third-order differentiation. (https://github.com/Oneflow-Inc/oneflow/pull/10188, https://github.com/Oneflow-Inc/oneflow/pull/10237)
-
Optimized conv interface implementation to support device and dtype parameters. (https://github.com/Oneflow-Inc/oneflow/pull/10228)
-
Optimized conv interface implementation to automatically expand input dimensions.(https://github.com/Oneflow-Inc/oneflow/pull/9721)
-
Optimized sum interface implementation to accommodate dtype parameters.(https://github.com/Oneflow-Inc/oneflow/pull/10204)
-
Optimized softmax interface implementation to support dtype parameters. (https://github.com/Oneflow-Inc/oneflow/pull/10069)
Changes and Fixes
1. Functional Changes
-
Removed deallocate context. (https://github.com/Oneflow-Inc/oneflow/pull/10143)
-
Removed debug compilation mode in graph compilation. (https://github.com/Oneflow-Inc/oneflow/pull/10145)
-
Removed unused logic for MemChain merge. (https://github.com/Oneflow-Inc/oneflow/pull/10097)
-
Removed default settings for some unused distributed environment variables. (https://github.com/Oneflow-Inc/oneflow/pull/9803)
-
Refactored collective boxing implementation under lazy mode. (https://github.com/Oneflow-Inc/oneflow/pull/10098)
-
Refactored registration of EagerCclS2S.(https://github.com/Oneflow-Inc/oneflow/pull/10100)
-
Refactored implementation of collective_boxing_executor_backend. (https://github.com/Oneflow-Inc/oneflow/pull/10082)
-
Refactored implementation of running global nn.graph using VM. (https://github.com/Oneflow-Inc/oneflow/pull/10048)
-
Refactored implementation of local to global related interfaces.(https://github.com/Oneflow-Inc/oneflow/pull/9870)
-
Refactored operator dispatch dialect implementation in MLIR codegen process. (https://github.com/Oneflow-Inc/oneflow/pull/9693)
-
Refactored implementation of random generator and distribution kernels. (https://github.com/Oneflow-Inc/oneflow/pull/9691)
-
Refactored implementation of fast_atomic_add operator. (https://github.com/Oneflow-Inc/oneflow/pull/9680)
-
Refactored error check related macros in glog. (https://github.com/Oneflow-Inc/oneflow/pull/10176)
-
Refactored implementation of random generator. (https://github.com/Oneflow-Inc/oneflow/pull/10025)
-
Refactored implementation of some elementwise primitive operations. (https://github.com/Oneflow-Inc/oneflow/pull/9857)
-
Refactored code related to device descriptions. (https://github.com/Oneflow-Inc/oneflow/pull/9791)
-
Refactored implementation of ParseDeviceString and ParseDeviceNameConf. (https://github.com/Oneflow-Inc/oneflow/pull/9833)
-
Refactored implementation of ActorMsg related functionalities, introducing IBVerbsActorMsgWrapper wrapper to reduce the size of ActorMsg. (https://github.com/Oneflow-Inc/oneflow/pull/9762)
-
Refactored implementation of save and load interfaces, migrating the method of saving graphs to the _save_graph function, adding some _open* helper classes to differentiate between paths and memory, enabling saving weights to BytesIO in save, and supporting file streaming in load. (https://github.com/Oneflow-Inc/oneflow/pull/10021)
2. Bug Fixes
-
Fixed default dynamic linking settings in CMake files to avoid LLVM15 linking errors. (https://github.com/Oneflow-Inc/oneflow/pull/10373, https://github.com/Oneflow-Inc/oneflow/pull/10131)
-
Fixed cast-related bugs in MLIR codegen. (https://github.com/Oneflow-Inc/oneflow/pull/10105)
-
Fixed logic handling for cpg attr in Module._apply function. (https://github.com/Oneflow-Inc/oneflow/pull/10343)
-
Fixed inheritance issue for DummyModule when attr is mro_entries. (https://github.com/Oneflow-Inc/oneflow/pull/9976)
-
Fixed size checking issue for _handle_size_arg in full op. (https://github.com/Oneflow-Inc/oneflow/pull/9975)
-
Fixed residual environment variables after launching mock via command line, causing subsequent API mock parameter errors. (https://github.com/Oneflow-Inc/oneflow/pull/9970)
-
Fixed inability to exit when two processes encounter exceptions. (https://github.com/Oneflow-Inc/oneflow/pull/10054)
-
Fixed bug in grouped quantization sbp derivation. (https://github.com/Oneflow-Inc/oneflow/pull/10132)
-
Fixed kMaxInputCount check issue in GroupedMatmulFunctor. (https://github.com/Oneflow-Inc/oneflow/pull/10322)
-
Fixed 0-size tensor broadcast issue.(https://github.com/Oneflow-Inc/oneflow/pull/10186)
-
Fixed issue where double type attr was not updated when using shared_graph. (https://github.com/Oneflow-Inc/oneflow/pull/10279)
-
Fixed data type error in GetItemInScalarTensor. (https://github.com/Oneflow-Inc/oneflow/pull/10226)
-
Fixed gradient issue in GroupNorm, calling GroupNormParamGrad only when gamma and beta gradients are required. (https://github.com/Oneflow-Inc/oneflow/pull/10045)
-
Fixed error when reading tensors with partial ranks in global mode. (https://github.com/Oneflow-Inc/oneflow/pull/10056)
-
Fixed control boundary issues in checkpointing under PP, affecting task graph construction under separate compilation. (https://github.com/Oneflow-Inc/oneflow/pull/10057)
-
Fixed bug when using 3D parallelism and enabling activation checkpointing simultaneously. (https://github.com/Oneflow-Inc/oneflow/pull/10031)
-
Fixed adaptation bug of AutoMixedPrecision pass on non-CUDA devices and bug related to device combinations in LayerNorm Module. (https://github.com/Oneflow-Inc/oneflow/pull/10026)
-
Fixed default value setting issue for reduce parameter in scatter operator. (https://github.com/Oneflow-Inc/oneflow/pull/10002)
-
Fixed incomplete disable of some Torch variables in mock.disable, causing lingering references in other globals. (https://github.com/Oneflow-Inc/oneflow/pull/9989)
Performance
1. OneFlow compile_from_torch VS PyTorch compile
Compile and execute the backbone parts of ResNet50 and Faster RCNN models using OneFlow compile_from_torch and PyTorch compile interfaces to test the compilation time with inputs of different shapes. The results are shown in the table below:
| Model | input shape | PyTorch compile | OneFlow compile_from_torch | dynamic | test timing | | ---- | ---------- | --------------- | ---------------------------- | ------- | -------- | | ResNet50 | (1, 3, 512, 512) | 21.328 s | 3.205 s | False | initial compilation and execution | | ResNet50 | (2, 3, 896, 512) | 14.167 s | 1.523 s | False | continuous compilation and execution | | ResNet50 | (2, 3, 512, 896) | 13.364 s | 1.402 s | False | continuous compilation and execution | | ResNet50 | (3, 3, 896, 896) | 15.056 s | 1.539 s | False | continuous compilation and execution | | ResNet50 | (2, 3, 1024, 896) | 14.167 s | 1.500 s | False | continuous compilation and execution | | ResNet50 | (2, 3, 896, 1024) | 12.891 s | 1.494 s | False | continuous compilation and execution | | ResNet50 | (6, 3, 1024, 1024) | 14.859 s | 1.872 s | False | continuous compilation and execution | | ResNet50 | (1, 3, 512, 512) | 170.446 s | 3.143 s | True | initial compilation and execution | | ResNet50 | (2, 3, 896, 512) | 185.672 s | 0.851 s | True | continuous compilation and execution | | ResNet50 | (2, 3, 512, 896) | 0.089 s | 0.836 s | True | continuous compilation and execution | | ResNet50 | (3, 3, 896, 896) | 0.084 s | 0.980 s | True | continuous compilation and execution | | ResNet50 | (2, 3, 1024, 896) | 0.077 s | 0.942 s | True | continuous compilation and execution | | ResNet50 | (2, 3, 896, 1024) | 0.080 s | 0.931 s | True | continuous compilation and execution | | ResNet50 | (6, 3, 1024, 1024) | 0.084 s | 1.406 s | True | continuous compilation and execution | | Faster RCNN | (1, 3, 512, 512) | 18.224 s | 5.483 s | False | initial compilation and execution | | Faster RCNN | (2, 3, 896, 512) | 9.200 s | 3.011 s | False | continuous compilation and execution | | Faster RCNN | (2, 3, 512, 896) | 9.331 s | 3.025 s | False | continuous compilation and execution | | Faster RCNN | (3, 3, 896, 896) | 9.301 s | 2.854 s | False | continuous compilation and execution | | Faster RCNN | (2, 3, 1024, 896) | 9.290 s | 2.805 s | False | continuous compilation and execution | | Faster RCNN | (2, 3, 896, 1024) | 9.123 s | 2.851 s | False | continuous compilation and execution | | Faster RCNN | (6, 3, 1024, 1024) | 9.377 s | 3.180 s | False | continuous compilation and execution | | Faster RCNN | (1, 3, 512, 512) | 25.444 s | 5.430 s | True | initial compilation and execution | | Faster RCNN | (2, 3, 896, 512) | 25.381 s | 1.899 s | True | continuous compilation and execution | | Faster RCNN | (2, 3, 512, 896) | 0.116 s | 1.886 s | True | continuous compilation and execution | | Faster RCNN | (3, 3, 896, 896) | 1.982 s | 1.793 s | True | continuous compilation and execution | | Faster RCNN | (2, 3, 1024, 896) | 0.114 s | 1.803 s | True | continuous compilation and execution | | Faster RCNN | (2, 3, 896, 1024) | 0.111 s | 1.778 s | True | continuous compilation and execution | | Faster RCNN | (6, 3, 1024, 1024) | 0.143 s | 2.110 s | True | continuous compilation and execution |
Using the OneFlow compile_from_torch and PyTorch compile interfaces, the unet section of the Stable Diffusion model was compiled and executed to test the compilation time and execution time with outputs of different shapes. The results are presented in the table below:
| Model | Output shape | PyTorch compile | OneFlow compile_from_torch | dynamic | test timing | | ---- | ---------- | --------------- | ---------------------------- | ------- | -------- | | Stable Diffusion | (2, 512, 512) | 103.701 s | 63.670 s | False | initial compilation and execution | | Stable Diffusion | (1, 512, 768) | 95.137 s | 53.864 s | False | continuous compilation and execution | | Stable Diffusion | (2, 768, 512) | 90.259 s | 55.271 s | False | continuous compilation and execution | | Stable Diffusion | (1, 768, 768) | 90.196 s | 51.590 s | False | continuous compilation and execution | | Stable Diffusion | (2, 512, 512) | 275.660 s | 57.117 s | True | initial compilation and execution | | Stable Diffusion | (1, 512, 768) | 345.774 s | 43.752 s | True | continuous compilation and execution | | Stable Diffusion | (2, 768, 512) | 349.835 s | 47.653 s | True | continuous compilation and execution | | Stable Diffusion | (1, 768, 768) | 7.224 s | 45.720 s | True | continuous compilation and execution | | Stable Diffusion | (2, 512, 512) | 4.088 s | 2.831 s | False | subsequent execution | | Stable Diffusion | (1, 512, 768) | 3.296 s | 2.325 s | False | subsequent execution | | Stable Diffusion | (2, 768, 512) | 5.594 s | 5.157 s | False | subsequent execution | | Stable Diffusion | (1, 768, 768) | 4.713 s | 3.557 s | False | subsequent execution | | Stable Diffusion | (2, 512, 512) | 4.448 s | 2.801 s | True | subsequent execution | | Stable Diffusion | (1, 512, 768) | 3.201 s | 2.314 s | True | subsequent execution | | Stable Diffusion | (2, 768, 512) | 6.093 s | 4.166 s | True | subsequent execution | | Stable Diffusion | (1, 768, 768) | 4.920 s | 3.557 s | True | subsequent execution |
Conclusion: The OneFlow compile_from_torch interface generally has shorter compilation times compared to the PyTorch compile interface. Additionally, benefiting from the exceptional operator optimizations in the OneFlow framework, there is superior execution performance on the Stable Diffusion model.
Note: The tests were conducted with GPU 3090, PyTorch v2.1.2 and CUDA 12.2.
2. OneFlow Eager vs PyTorch Eager
| Model | GPU model | number of GPUs | macro batch | PyTorch performance(iter/s) | OneFlow performance(iter/s) | speedup ratio | | ---- | -------- | --- | ----------- | -------------------- | -------------------- | ------ | | ResNet50 | 3090 | 1 | 1 | 31.37 | 38.81 | 23.72% | | ResNet50 | 3090 | 1 | 2 | 32.06 | 48.45 | 51.12% | | ResNet50 | 3090 | 2 | 1 | 31.10 | 33.46 | 7.59% | | ResNet50 | 3090 | 2 | 2 | 31.76 | 34.83 | 9.67% | | ResNet50 | A100 | 1 | 1 | 24.60 | 46.64 | 89.59% | | ResNet50 | A100 | 1 | 2 | 25.06 | 49.88 | 99.04% | | ResNet50 | A100 | 2 | 1 | 25.28 | 39.18 | 54.98% | | ResNet50 | A100 | 2 | 2 | 24.09 | 32.84 | 36.32% | | Bert | 3090 | 1 | 1 | 8.93 | 10.41 | 16.57% | | Bert | 3090 | 1 | 2 | 13.11 | 14.31 | 9.15% | | Bert | 3090 | 2 | 1 | 6.94 | 8.27 | 19.16% | | Bert | 3090 | 2 | 2 | 12.19 | 15.58 | 27.81% | | Bert | A100 | 1 | 1 | 10.45 | 12.72 | 21.72% | | Bert | A100 | 1 | 2 | 20.24 | 21.57 | 6.57% | | Bert | A100 | 2 | 1 | 12.63 | 16.09 | 27.39% | | Bert | A100 | 2 | 2 | 24.86 | 29.84 | 20.03% |
Conclusion: Compared to PyTorch Eager, using OneFlow Eager shows significant performance advantages in small batch scenarios for both ResNet50 and BERT models.
Note: The tests were conducted using PyTorch v2.1.0 and CUDA 12.1.
Version 1.0.0
OneFlow v1.0.0 release note
OneFlow 发布 v1.0.0 版本, 欢迎大家安装使用。
- 重点内容
- 新特性
- 功能改进
- 改动与修复
- 性能
重点内容
本次版本更新包含 447 个 commits 和如下重点内容:
-
发布新接口
compile_from_torch。该接口在共享参数显存的情况下,将 PyTorch 的 Module 实例转化成 OneFlow 的 Module 实例,支持直接 Eager 运行或者转化为静态图 nn.Graph 并进一步使用 MLIR 编译加速。该接口仍在快速演进中,目前支持了动态形状编译并在ResNet50、Faster RCNN、Stable Diffusion三个典型模型上做了验证。 -
对 Eager 运行时做了一系列优化与重构,包括统一系统内存池、对接 CUDA 原生接口、优化指令调度机制、引入指令融合机制、优化 Autograd 构图速度、优化 Op 推导过程、解耦 Instruction 与 Stream 等。
-
静态图分布式物理执行计划支持分离编译功能,每个进程独立编译自己所需的执行计划,使得编译时间不再随 GPU 规模线性增长。
-
新增一系列函数式自动微分相关接口支持,包括 jvp、vjp、hvp、vhp、jacobian、hessian。
-
新增 Insight 模块,支持可视化地展示埋点区间内 kernel 调用、执行时间、速度等信息。
-
大规模模型训练开源工具箱 LiBai 版本更新,原生支持大语言模型 Llama2 和 ChatGLM2 的 finetune 和分布式推理,支持 full finetune、adapter finetune、lora finetune,可使用 lm-eval-harness 对语言模型进行评测验证。
-
OneFlow Serving 功能升级,在原有支持 OneFlow Cpp 后端的基础上,新增支持 OneFlow Python 后端和 OneFlow Lite 后端。
新特性
1、compile_from_torch
compile_from_torch 接口在共享参数显存的情况下,将 PyTorch 的 Module 实例转化成 OneFlow 的 Module 实例,支持直接 Eager 运行或者转化为静态图 nn.Graph 并进一步使用 MLIR 编译加速。(https://github.com/Oneflow-Inc/oneflow/pull/10404, https://github.com/Oneflow-Inc/oneflow/pull/10408, https://github.com/Oneflow-Inc/oneflow/pull/9984, https://github.com/Oneflow-Inc/oneflow/pull/9754)
接口签名及参数介绍:
compile_from_torch(torch_module: torch.nn.Module, \*, use_graph=True, options={})
* torch_module:需要被转换的 Torch Module 实例。
* use_graph:是否转化为静态图 nn.Graph 并使用 MLIR 编译加速,默认为 True。
* options:
* size: 使用静态图 nn.Graph 后会根据输入的 shape 计算 hash 值缓存相应的 graph ,size 表示静态图缓存的最大容量,超过最大容量会根据 LRU 策略对 graph 进行清理,默认值为 9。
* dynamic:对于动态 shape 的输入第一次会完整编译 graph,之后的对于不同 shape 的输入当 dynamic 为 True 时会启用共享图进行编译加速,dynamic 为 False 时每次都会重新进行编译,默认为 True。
* debug:调试模式和日志级别设置,-1 禁用调试模式,0 输出警告和静态图构建信息,1 额外输出每个子模块的构图信息,2 额外输出每个算子的进度,3 输出更详细的算子信息,默认为 -1。
使用示例:
import torch
from torchvision import models
import oneflow
from oneflow.framework.infer_compiler import compile_from_torch
DEVICE = torch.device("cuda")
WEIGHT = models.ResNet50_Weights.DEFAULT
model = models.resnet50(weights=WEIGHT).to(DEVICE)
compile_model = compile_from_torch(model, options={"dynamic": True})
2、分离编译
静态图分布式物理执行计划支持分离编译功能,每个进程独立编译自己所需的执行计划,使得编译时间不再随 GPU 规模线性增长。分离编译功能支持 3D 混合并行(数据并行+模型并行+流水并行)场景,可与大规模模型训练开源工具箱 LiBai 一同使用,打开方式为:export ONEFLOW_ENABLE_LAZY_SEPARATE_COMPILE=1。(https://github.com/Oneflow-Inc/oneflow/pull/9920, https://github.com/Oneflow-Inc/oneflow/pull/10140, https://github.com/Oneflow-Inc/oneflow/pull/10141, https://github.com/Oneflow-Inc/oneflow/pull/10124, https://github.com/Oneflow-Inc/oneflow/pull/10102)
以下是在 128 卡 A100-PCIE-40GB 设备上,配合 LiBai 在 GPT2 模型上的测试结果: | 并行方式 | 是否开启分离编译 | 执行计划编译时间 | | ------- | ---------------------------- | ----------------------- | | 数据并行 (DP128 MP1 PP1) | 否 | 超过 20 minutes | | 数据并行 (DP128 MP1 PP1) | 是 | 108.21 s | | 3D 并行 (DP4 MP4 PP8) | 否 | 445.16 s | | 3D 并行 (DP4 MP4 PP8) | 是 | 82.88 s |
3、函数式自动微分接口
新增一系列函数式自动微分相关接口支持,包括 jvp、vjp、hvp、vhp、jacobian、hessian。(https://github.com/Oneflow-Inc/oneflow/pull/10412, https://github.com/Oneflow-Inc/oneflow/pull/10428)
使用示例:
import oneflow as flow
# jacobian example
def exp_reducer(x):
return x.exp().sum(dim=1)
input = flow.rand(2, 2)
jac_rslt = flow.autograd.functional.jacobian(exp_reducer, input)
# vhp example
def pow_reducer(x):
return x.pow(3).sum()
input = flow.rand(2, 2)
v = flow.ones(2, 2)
vhp_rslt = flow.autograd.functional.vhp(pow_reducer, input, v)
4、Insight模块
新增 Insight 模块,支持可视化地展示埋点区间内 kernel 调用、执行时间、速度等信息。(https://github.com/Oneflow-Inc/oneflow/pull/10370)
使用方法如下:
- 步骤一:使用 OneFlow Profiler 模块在代码中设置埋点区间。
- 步骤二:运行代码并使用 NVIDIA Nsight Systems 生成 sqlite 后缀文件。
- 步骤三:使用 OneFlow Insight 模块生成 json 文件。
- 步骤四:在网址 chrome://tracing/ 或 edge://tracing/ 中打开 json 文件得到可视化界面。
更详细的介绍可参考:https://github.com/Oneflow-Inc/oneflow/tree/master/python/oneflow/utils/insight#usage
5、LiBai版本更新
-
大规模模型训练开源工具箱 LiBai 功能升级,发布新版本 v0.3.0,原生支持大语言模型 Llama2 和 ChatGLM2 的 finetune 和分布式推理,支持 full finetune、adapter finetune、lora finetune,可使用 lm-eval-harness 对语言模型进行评测验证。
-
ChatGLM 和 Llama2 的分布式训练和推理支持情况如下:
| Models | 2D (tp+pp) Inference | 3D Parallel Training |
|---|---|---|
| ChatGLM | ✔ | ✔ |
| Llama2 | ✔ | ✔ |
使用示例:
# full finetune
bash tools/train.sh projects/Llama/train_net.py projects/Llama/configs/llama_sft.py 8
# adapter finetune
bash tools/train.sh projects/Llama/adapter/train_net.py projects/Llama/adapter/adapter_sft.py 8
# inference
bash tools/infer.sh projects/Llama/pipeline.py 8
# eval
python projects/Llama/utils/eval_adapter.py
6、其他新特性
- 新增 FFT 相关算子。(https://github.com/Oneflow-Inc/oneflow/pull/10027)
- 新增 zeta 算子。(https://github.com/Oneflow-Inc/oneflow/pull/10189)
- 新增 tril_ 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9996)
- 新增 clone 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9800)
- 新增 frac、frac_ 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9979)
- 新增 exp2 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9958)
- 新增 rrelu 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9736)
- 新增 lgamma 反向算子。(https://github.com/Oneflow-Inc/oneflow/pull/10177)
- 新增 digamma 算子。(https://github.com/Oneflow-Inc/oneflow/pull/10066)
- 新增 trigamma 算子。(https://github.com/Oneflow-Inc/oneflow/pull/10117)
- 新增 bitwise_not 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9859)
- 新增 squared_relu 算子。(https://github.com/Oneflow-Inc/oneflow/pull/10316)
- 新增 skip_rms_norm 算子。(https://github.com/Oneflow-Inc/oneflow/pull/10036)
- 新增 multi_tensor_amp_grad_scaler 相关算子。(https://github.com/Oneflow-Inc/oneflow/pull/10071)
- 新增 bitwise_and、bitwise_or、bitwise_xor 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9842)
- 新增 fused_attention_concat_past_key_value 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9963)
- 新增 fused_multi_head_attention_inference_v2 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9933)
- 新增 fused_codegeex_qkv_reshape 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9927)
- 新增 fused_apply_rotary_emb 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9914)
- 新增 skip_layer_norm 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9906)
- 新增 groupwise_dequantize、fused_linear_with_groupwise_quantized_weight 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9900)
- 新增 fused_scale_mask_bias_softmax、fused_scale_mask_bias_softmax_grad 算子。(https://github.com/Oneflow-Inc/oneflow/pull/9867)
- 新增 depend 算子,用于描述计算图中依赖关系。(https://github.com/Oneflow-Inc/oneflow/pull/9807)
- 新增 real, imag, conj, conj_physical 复数数据类型相关算子。(https://github.com/Oneflow-Inc/oneflow/pull/10034, https://github.com/Oneflow-Inc/oneflow/pull/10281)
- 新增 nms 算子 cpu 支持。(https://github.com/Oneflow-Inc/oneflow/pull/10225)
- 新增 cast 算子对 bool to int16 数据类型转换支持。(https://github.com/Oneflow-Inc/oneflow/pull/10211)
- 新增 arange 算子对 fp16 数据类型的支持。(https://github.com/Oneflow-Inc/oneflow/pull/10019)
- 新增 adaptive_avg_pool 算子对 fp16 数据类型的支持。(https://github.com/Oneflow-Inc/oneflow/pull/10004)
- 新增 nonzero 算子对 fp16 数据类型的支持。(https://github.com/Oneflow-Inc/oneflow/pull/9826)
- 新增 exponential 算子对 half 数据类型的支持。(https://github.com/Oneflow-Inc/oneflow/pull/10005)
- 新增 arg_sort、top_k 算子对 half 数据类型的支持。(https://github.com/Oneflow-Inc/oneflow/pull/10000)
功能改进
1、Eager 运行时优化与重构
对 Eager 运行时做了一系列优化与重构,主要包括:
- 统一系统内存池,打通同设备下的所有分配器的内存资源。(https://github.com/Oneflow-Inc/oneflow/pull/8591)
- 对接 CUDA 原生接口,加速 kernel launch。(https://github.com/Oneflow-Inc/oneflow/pull/8571)
- 优化指令调度机制,降低系统负担。(https://github.com/Oneflow-Inc/oneflow/pull/8796)
- 引入指令融合机制,加速指令分发。(https://github.com/Oneflow-Inc/oneflow/pull/7399)
- 优化 Autograd 构图部分的速度。(https://github.com/Oneflow-Inc/oneflow/pull/8606)
- 优化op推导过程,加速kernel执行。(https://github.com/Oneflow-Inc/oneflow/pull/8672, https://github.com/Oneflow-Inc/oneflow/pull/8619, https://github.com/Oneflow-Inc/oneflow/pull/8662)
- 合并eager运行时中的冗余概念,解耦Instruction与Stream。(https://github.com/Oneflow-Inc/oneflow/pull/8583, https://github.com/Oneflow-Inc/oneflow/pull/8590, https://github.com/Oneflow-Inc/oneflow/pull/7607)
可以通过一些环境变量设定 Eager 运行时行为:
| 环境变量 | 意义 | 默认值 | | ------- | ---------------------------- | ----------------------- | | ONEFLOW_VM_COMPUTE_ON_WORKER_THREAD | 是否在 worker 线程上完成计算 | true | | ONEFLOW_VM_MULTI_THREAD | 是否使用多线程协同执行 Eager 运算 | true| | ONEFLOW_VM_ENABLE_STREAM_WAIT | 多 stream 间的依赖是否使用 stream_wait 机制 | true | | ONEFLOW_VM_ENABLE_SCHEDULE_YIELD| 是否使用 yield 机制减少 scheduler 线程 busy wait 程度 | true| | ONEFLOW_EAGER_ENABLE_LOCAL_INFER_CACHE | 计算过程中是否缓存算子输出的元信息 | true | | ONEFLOW_VM_WORKER_THREAD_LIMIT| worker 线程的个数 | 16 | | ONEFLOW_VM_PENDING_HANDLE_WINDOW_SIZE | vm 融合指令的最大 size |10| | ONEFLOW_VM_BLOCKING_DEBUG_INSTRUCTIONS_DISPLAY_LIMIT| vm 执行超时时打印未处理指令的数量 | 1000 |
2、OneFlow Serving功能升级
OneFlow Serving 功能升级,在原有支持 OneFlow Cpp 后端的基础上,新增支持 OneFlow Python 后端和 OneFlow Lite 后端。
- 使用 OneFlow Cpp 后端可以在脱离 Python 的环境中部署以达到最高的性能。
- 使用 OneFLow Lite 后端可以实现在端侧设备上的部署。
- 使用 OneFlow Python 后端可以以极小的迁移代价完成复杂模型的部署。
使用方法参考:https://github.com/Oneflow-Inc/serving/blob/main/README.md
3、其他功能改进
- 改进部分代码实现以支持 cuda 12.x 版本。(https://github.com/Oneflow-Inc/oneflow/pull/10367)
- 改进 glu 算子实现,支持无bias 输入。(https://github.com/Oneflow-Inc/oneflow/pull/9874)
- 改进池化算子实现,支持 channels_last 参数 。(https://github.com/Oneflow-Inc/oneflow/pull/10242)
- 改进 flip 算子实现,针对 dim = -1 时候访存无法合并的情况进行优化。(https://github.com/Oneflow-Inc/oneflow/pull/10310)
- 改进 bincount 算子实现,实现优化加速。(https://github.com/Oneflow-Inc/oneflow/pull/10308)
- 改进 index_add 算子实现,根据 index 的长度派发不同的实现逻辑以改善索引比较小的时候的性能。(https://github.com/Oneflow-Inc/oneflow/pull/9751)
- 改进 topk 算子实现,优化 batch_size 是1时的性能。(https://github.com/Oneflow-Inc/oneflow/pull/10009)
- 改进 conv、arange 等算子实现,支持启用cuda graph。(https://github.com/Oneflow-Inc/oneflow/pull/9761)
- 改进 upsample 算子实现,增加对输入/输出大小检查。(https://github.com/Oneflow-Inc/oneflow/pull/9737)
- 改进 grouped_matmul_bias 算子实现,增加张量并行的 sbp 推导规则。(https://github.com/Oneflow-Inc/oneflow/pull/9934)
- 改进 reshape 算子实现,增加对 nd sbp 推导规则。(https://github.com/Oneflow-Inc/oneflow/pull/9858)
- 改进 mask_fill 和 in_top_k 算子的报错信息并完善测试样例。(https://github.com/Oneflow-Inc/oneflow/pull/10062)
- 改进 tanh 算子的高阶微分规则,优化三阶微分下的性能。(https://github.com/Oneflow-Inc/oneflow/pull/10188, https://github.com/Oneflow-Inc/oneflow/pull/10237)
- 改进 conv 接口实现,支持 device 和 dtype 参数。(https://github.com/Oneflow-Inc/oneflow/pull/10228)
- 改进 conv 接口实现,支持对输入自动扩展维度。(https://github.com/Oneflow-Inc/oneflow/pull/9721)
- 改进 sum 接口实现,支持 dtype 参数。(https://github.com/Oneflow-Inc/oneflow/pull/10204)
- 改进 softmax 接口实现,支持 dtype 参数。(https://github.com/Oneflow-Inc/oneflow/pull/10069)
- 改进 maxpool 接口实现,支持 3D 输入张量。(https://github.com/Oneflow-Inc/oneflow/pull/10110)
- 改进 ctc_loss 接口实现,参数与 PyTorch 接口对齐。(https://github.com/Oneflow-Inc/oneflow/pull/9887)
- 改进 copy 接口实现,支持输入和输出的 device 和 dtype 都不同的情况。(https://github.com/Oneflow-Inc/oneflow/pull/9888)
- 改进 grad 接口实现,支持 allow_unused 参数。(https://github.com/Oneflow-Inc/oneflow/pull/10251)
- 改进 load 接口实现,提供更加用户友好的报错信息。(https://github.com/Oneflow-Inc/oneflow/pull/10138)
- 改进 fused_matmul_bias 算子及接口实现,支持 alpha 和 beta 参数。(https://github.com/Oneflow-Inc/oneflow/pull/10015)
- 改进 normal 算子及接口实现以和 pytorch 行为对齐。(https://github.com/Oneflow-Inc/oneflow/pull/10185)
- 改进 fused attention 算子及接口实现,允许 pasti_key 和 past_value 为 None 的情况。(https://github.com/Oneflow-Inc/oneflow/pull/9977)
- 改进 fused_attention 算子及接口实现,增加对可变序列长度的支持。(https://github.com/Oneflow-Inc/oneflow/pull/9991)
- 改进 fused_multi_head_attention_inference 算子及接口实现,增加attn_bias 参数。(https://github.com/Oneflow-Inc/oneflow/pull/9853)
- 改进 bn 相关 functor 实现,融合bn_add_relu和bn_relu操作加速推理。(https://github.com/Oneflow-Inc/oneflow/pull/10239)
- 改进基于 MLIR CodeGen 流程,将 LLVM 版本更新到 16.0.0。(https://github.com/Oneflow-Inc/oneflow/pull/9985)
改动与修复
1、功能改动
- 移除 deallocate context。(https://github.com/Oneflow-Inc/oneflow/pull/10143)
- 移除图编译中的调试编译模式。(https://github.com/Oneflow-Inc/oneflow/pull/10145)
- 移除不再使用的 MemChain merge 的逻辑。(https://github.com/Oneflow-Inc/oneflow/pull/10097)
- 移除一些分布式相关的环境变量的默认设置。(https://github.com/Oneflow-Inc/oneflow/pull/9803)
- 重构 lazy 模式下的 collective boxing 实现。(https://github.com/Oneflow-Inc/oneflow/pull/10098)
- 重构 EagerCclS2S 的注册。(https://github.com/Oneflow-Inc/oneflow/pull/10100)
- 重构 collective_boxing_executor_backend 的实现。(https://github.com/Oneflow-Inc/oneflow/pull/10082)
- 重构使用 VM 跑 global nn.graph 的实现。(https://github.com/Oneflow-Inc/oneflow/pull/10048)
- 重构 local to global 相关接口实现。(https://github.com/Oneflow-Inc/oneflow/pull/9870)
- 重构 MLIR codegen 流程中算子分发 dialect 实现。(https://github.com/Oneflow-Inc/oneflow/pull/9693)
- 重构 random generator 和 distribution kernels 实现。(https://github.com/Oneflow-Inc/oneflow/pull/9691)
- 重构 fast_atomic_add 算子实现。(https://github.com/Oneflow-Inc/oneflow/pull/9680)
- 重构 glog 中的错误检查相关宏定义。(https://github.com/Oneflow-Inc/oneflow/pull/10176)
- 重构 random generator 实现。(https://github.com/Oneflow-Inc/oneflow/pull/10025)
- 重构部分 elementwise primitive 的实现。(https://github.com/Oneflow-Inc/oneflow/pull/9857)
- 重构部分 device 描述相关代码。(https://github.com/Oneflow-Inc/oneflow/pull/9791)
- 重构 ParseDeviceString 和 ParseDeviceNameConf 实现。(https://github.com/Oneflow-Inc/oneflow/pull/9833)
- 重构 ActorMsg 相关实现,引入 IBVerbsActorMsgWrapper 封装以减少 ActorMsg 的大小。(https://github.com/Oneflow-Inc/oneflow/pull/9762)
- 重构 save 和 load 接口实现,迁移保存 Graph 逻辑的方法到 _save_graph 函数,添加部分 _open* 辅助类区分路径和内存, save 支持将权重保存到 BytesIO 中,load 支持文件流。(https://github.com/Oneflow-Inc/oneflow/pull/10021)
- 重构部分 tensor 相关接口实现,代码从 python 层迁移到 C++ 层。(https://github.com/Oneflow-Inc/oneflow/pull/9990, https://github.com/Oneflow-Inc/oneflow/pull/9964)
- 升级项目使用的 PyBind 版本至 2.11.1。(https://github.com/Oneflow-Inc/oneflow/pull/10391)
2、问题修复
- 修复 cmake 文件中动态链接默认设置以避免 llvm15 链接错误。(https://github.com/Oneflow-Inc/oneflow/pull/10373, https://github.com/Oneflow-Inc/oneflow/pull/10131)
- 修复基于 MLIR codegen 中 cast 相关 bug。(https://github.com/Oneflow-Inc/oneflow/pull/10105)
- 修复 Module._apply 函数中对 cpg attr 处理的逻辑问题。(https://github.com/Oneflow-Inc/oneflow/pull/10343)
- 修复 DummyModule 在 attr 为 __mro_entries__ 情况下无法被继承的问题。(https://github.com/Oneflow-Inc/oneflow/pull/9976)
- 修复 full op 中 _handle_size_arg 对传入 size 判断的问题。(https://github.com/Oneflow-Inc/oneflow/pull/9975)
- 修复通过命令行启动 mock 后环境变量残留导致后续 api 方式的 mock 参数错误的问题。(https://github.com/Oneflow-Inc/oneflow/pull/9970)
- 修复两个进程异常时无法退出的问题。(https://github.com/Oneflow-Inc/oneflow/pull/10054)
- 修复了分组量化 sbp 推导的 bug。(https://github.com/Oneflow-Inc/oneflow/pull/10132)
- 修复 GroupedMatmulFunctor 中的 kMaxInputCount 检查问题。(https://github.com/Oneflow-Inc/oneflow/pull/10322)
- 修复 0-size tensor broadcast 的问题。(https://github.com/Oneflow-Inc/oneflow/pull/10186)
- 修复使用 shared_graph 时 double 类型 attr 没有更新的问题。(https://github.com/Oneflow-Inc/oneflow/pull/10279)
- 修复 GetItemInScalarTensor 中的数据类型错误。(https://github.com/Oneflow-Inc/oneflow/pull/10226)
- 修复 GroupNorm 梯度问题,仅当 gamma 和 beta 需要梯度时,才调用 GroupNormParamGrad。(https://github.com/Oneflow-Inc/oneflow/pull/10045)
- 修复 global mode 在读取 placement 为部分 ranks 的 tensor 时会报错的问题。(https://github.com/Oneflow-Inc/oneflow/pull/10056)
- 修复 checkpointing 在 PP 下可能会有跨出 rank 控制的边,从而导致影响分离编译下的 task graph 构建的问题。(https://github.com/Oneflow-Inc/oneflow/pull/10057)
- 修复同时使用 3D 并行和打开 activation checkpointing 时的 bug。(https://github.com/Oneflow-Inc/oneflow/pull/10031)
- 修复 AutoMixedPrecision pass 在其他非 cuda 设备上的适配 bug 和 LayerNorm Module相关设备组合的 bug。(https://github.com/Oneflow-Inc/oneflow/pull/10026)
- 修复 scatter 算子 reduce 参数默认值设置问题。(https://github.com/Oneflow-Inc/oneflow/pull/10002)
- 修复 mock.disable 时,有些 Torch 变量依旧内置于其他引用的 globals 里而导致 disable 不彻底的问题。(https://github.com/Oneflow-Inc/oneflow/pull/9989)
- 修复 vm::TensorStorage 析构问题。(https://github.com/Oneflow-Inc/oneflow/pull/9962)
- 修复 offload,解决小 tensor 释放清理不出 Cuda Memory 的问题。(https://github.com/Oneflow-Inc/oneflow/pull/9974)
- 修复线程不安全导致的 Python stack getter 偶发 segmentation fault 的问题。(https://github.com/Oneflow-Inc/oneflow/pull/9955)
- 修复分离编译场景下的 set 中元素查找不到的问题。(https://github.com/Oneflow-Inc/oneflow/pull/9952)
- 修复 fused_multi_head_attention 算子,对齐 qkv 和 output_layout。(https://github.com/Oneflow-Inc/oneflow/pull/9950)
- 修复 random 系列算子在 graph 和 checkpointing 中 seed 表现不一致的问题。(https://github.com/Oneflow-Inc/oneflow/pull/9941)
- 修复 Eager 模式下 parameter reload 失败问题。(https://github.com/Oneflow-Inc/oneflow/pull/9935)
- 修复 mock torch lazy 功能特定情况下死循环的问题。(https://github.com/Oneflow-Inc/oneflow/pull/9926)
性能
1、OneFlow compile_from_torch VS PyTorch compile
对 ResNet50 模型和 Faster RCNN 模型的 backbone 部分使用 OneFlow compile_from_torch 和 PyTorch compile 接口进行编译并执行,测试不同 shape 输入时的编译时间,结果如下表:
| 模型 | 输入 shape | PyTorch compile | OneFlow compile_from_torch | dynamic | 测试时机 | | ---- | ---------- | --------------- | ---------------------------- | ------- | -------- | | ResNet50 | (1, 3, 512, 512) | 21.328 s | 3.205 s | False | 首次编译执行 | | ResNet50 | (2, 3, 896, 512) | 14.167 s | 1.523 s | False | 连续编译执行 | | ResNet50 | (2, 3, 512, 896) | 13.364 s | 1.402 s | False | 连续编译执行 | | ResNet50 | (3, 3, 896, 896) | 15.056 s | 1.539 s | False | 连续编译执行 | | ResNet50 | (2, 3, 1024, 896) | 14.167 s | 1.500 s | False | 连续编译执行 | | ResNet50 | (2, 3, 896, 1024) | 12.891 s | 1.494 s | False | 连续编译执行 | | ResNet50 | (6, 3, 1024, 1024) | 14.859 s | 1.872 s | False | 连续编译执行 | | ResNet50 | (1, 3, 512, 512) | 170.446 s | 3.143 s | True | 首次编译执行 | | ResNet50 | (2, 3, 896, 512) | 185.672 s | 0.851 s | True | 连续编译执行 | | ResNet50 | (2, 3, 512, 896) | 0.089 s | 0.836 s | True | 连续编译执行 | | ResNet50 | (3, 3, 896, 896) | 0.084 s | 0.980 s | True | 连续编译执行 | | ResNet50 | (2, 3, 1024, 896) | 0.077 s | 0.942 s | True | 连续编译执行 | | ResNet50 | (2, 3, 896, 1024) | 0.080 s | 0.931 s | True | 连续编译执行 | | ResNet50 | (6, 3, 1024, 1024) | 0.084 s | 1.406 s | True | 连续编译执行 | | Faster RCNN | (1, 3, 512, 512) | 18.224 s | 5.483 s | False | 首次编译执行 | | Faster RCNN | (2, 3, 896, 512) | 9.200 s | 3.011 s | False | 连续编译执行 | | Faster RCNN | (2, 3, 512, 896) | 9.331 s | 3.025 s | False | 连续编译执行 | | Faster RCNN | (3, 3, 896, 896) | 9.301 s | 2.854 s | False | 连续编译执行 | | Faster RCNN | (2, 3, 1024, 896) | 9.290 s | 2.805 s | False | 连续编译执行 | | Faster RCNN | (2, 3, 896, 1024) | 9.123 s | 2.851 s | False | 连续编译执行 | | Faster RCNN | (6, 3, 1024, 1024) | 9.377 s | 3.180 s | False | 连续编译执行 | | Faster RCNN | (1, 3, 512, 512) | 25.444 s | 5.430 s | True | 首次编译执行 | | Faster RCNN | (2, 3, 896, 512) | 25.381 s | 1.899 s | True | 连续编译执行 | | Faster RCNN | (2, 3, 512, 896) | 0.116 s | 1.886 s | True | 连续编译执行 | | Faster RCNN | (3, 3, 896, 896) | 1.982 s | 1.793 s | True | 连续编译执行 | | Faster RCNN | (2, 3, 1024, 896) | 0.114 s | 1.803 s | True | 连续编译执行 | | Faster RCNN | (2, 3, 896, 1024) | 0.111 s | 1.778 s | True | 连续编译执行 | | Faster RCNN | (6, 3, 1024, 1024) | 0.143 s | 2.110 s | True | 连续编译执行 |
对 Stable Diffusion 模型的 unet 部分使用 OneFlow compile_from_torch 和 PyTorch compile 接口进行编译并执行,测试不同 shape 输出时的编译时间和推理时间,结果如下表:
| 模型 | 输出 shape | PyTorch compile | OneFlow compile_from_torch | dynamic | 测试时机 | | ---- | ---------- | --------------- | ---------------------------- | ------- | -------- | | Stable Diffusion | (2, 512, 512) | 103.701 s | 63.670 s | False | 首次编译执行 | | Stable Diffusion | (1, 512, 768) | 95.137 s | 53.864 s | False | 连续编译执行 | | Stable Diffusion | (2, 768, 512) | 90.259 s | 55.271 s | False | 连续编译执行 | | Stable Diffusion | (1, 768, 768) | 90.196 s | 51.590 s | False | 连续编译执行 | | Stable Diffusion | (2, 512, 512) | 275.660 s | 57.117 s | True | 首次编译执行 | | Stable Diffusion | (1, 512, 768) | 345.774 s | 43.752 s | True | 连续编译执行 | | Stable Diffusion | (2, 768, 512) | 349.835 s | 47.653 s | True | 连续编译执行 | | Stable Diffusion | (1, 768, 768) | 7.224 s | 45.720 s | True | 连续编译执行 | | Stable Diffusion | (2, 512, 512) | 4.088 s | 2.831 s | False | 后续执行 | | Stable Diffusion | (1, 512, 768) | 3.296 s | 2.325 s | False | 后续执行 | | Stable Diffusion | (2, 768, 512) | 5.594 s | 5.157 s | False | 后续执行 | | Stable Diffusion | (1, 768, 768) | 4.713 s | 3.557 s | False | 后续执行 | | Stable Diffusion | (2, 512, 512) | 4.448 s | 2.801 s | True | 后续执行 | | Stable Diffusion | (1, 512, 768) | 3.201 s | 2.314 s | True | 后续执行 | | Stable Diffusion | (2, 768, 512) | 6.093 s | 4.166 s | True | 后续执行 | | Stable Diffusion | (1, 768, 768) | 4.920 s | 3.557 s | True | 后续执行 |
结论:使用 OneFlow compile_from_torch 接口有相对于 PyTorch compile 接口平均更短的编译时间,另外得益于 OneFlow 框架中极致的算子优化,在 Stable Diffusion 模型上有更优的执行性能。
备注:测试使用 GPU 型号为 3090,PyTorch 版本为 v2.1.2,cuda 版本为 12.2。
2、OneFlow Eager vs PyTorch Eager
| 模型 | GPU 型号 | 卡数 | macro batch | PyTorch 性能(iter/s) | OneFlow 性能(iter/s) | 加速比 | | ---- | -------- | --- | ----------- | -------------------- | -------------------- | ------ | | ResNet50 | 3090 | 1 | 1 | 31.37 | 38.81 | 23.72% | | ResNet50 | 3090 | 1 | 2 | 32.06 | 48.45 | 51.12% | | ResNet50 | 3090 | 2 | 1 | 31.10 | 33.46 | 7.59% | | ResNet50 | 3090 | 2 | 2 | 31.76 | 34.83 | 9.67% | | ResNet50 | A100 | 1 | 1 | 24.60 | 46.64 | 89.59% | | ResNet50 | A100 | 1 | 2 | 25.06 | 49.88 | 99.04% | | ResNet50 | A100 | 2 | 1 | 25.28 | 39.18 | 54.98% | | ResNet50 | A100 | 2 | 2 | 24.09 | 32.84 | 36.32% | | Bert | 3090 | 1 | 1 | 8.93 | 10.41 | 16.57% | | Bert | 3090 | 1 | 2 | 13.11 | 14.31 | 9.15% | | Bert | 3090 | 2 | 1 | 6.94 | 8.27 | 19.16% | | Bert | 3090 | 2 | 2 | 12.19 | 15.58 | 27.81% | | Bert | A100 | 1 | 1 | 10.45 | 12.72 | 21.72% | | Bert | A100 | 1 | 2 | 20.24 | 21.57 | 6.57% | | Bert | A100 | 2 | 1 | 12.63 | 16.09 | 27.39% | | Bert | A100 | 2 | 2 | 24.86 | 29.84 | 20.03% |
结论:使用 OneFlow Eager 相对于 PyTorch Eager 在 ResNet50 和 Bert 两个模型小 batch 场景下有明显性能优势。
备注:测试使用PyTorch版本为 v2.1.0,cuda 版本为 12.1。