-
Notifications
You must be signed in to change notification settings - Fork 142
Machine Learning Integration for DaCe (Autodiff - ONNX - PyTorch) #2164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
affifboudaoud
wants to merge
228
commits into
main
Choose a base branch
from
dace_ad
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Removed the redundant ReverseReduceMax class and its methods, which duplicated functionality from ReverseReduce. Updated import statements and cleaned up the code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request: Machine Learning Integration for DaCe
Overview
This PR adds comprehensive machine learning capabilities to DaCe through three tightly integrated components:
Together, these components enable DaCe to optimize and accelerate machine learning workloads, particularly neural network training and inference.
High-Level Architecture
Component 1: Automatic Differentiation (
dace/autodiff/
)Purpose
Provides reverse-mode automatic differentiation for SDFGs, enabling gradient computation for any DaCe program. This is the foundation for neural network training and gradient-based optimization.
Key Capabilities
Core Algorithm
Key Files
backward_pass_generator.py
implementations/onnx_ops.py
implementations/dace_nodes.py
data_forwarding/manager.py
Component 2: ONNX Integration (
dace/libraries/onnx/
)Purpose
Enables importing and executing ONNX neural network models within DaCe. Converts ONNX graphs to optimized DaCe SDFGs for efficient execution on CPU/GPU.
Key Capabilities
Core Architecture
Dynamic Node Generation:
ONNXConv
,ONNXMatMul
,ONNXSoftmax
(100+ generated classes)Implementation Strategies:
pure_implementations.py
): Reference implementations in Python/NumPyimg_op_implementations.py
): Hand-crafted SDFGs for performanceImport Pipeline:
Key Files
onnx_importer.py
op_implementations/pure_implementations.py
nodes/onnx_op_registry.py
schema.py
shape_inference/symbolic_shape_infer.py
Component 3: PyTorch Integration (
dace/libraries/torch/
)Purpose
Provides bidirectional integration between PyTorch and DaCe. Enables optimizing PyTorch models with DaCe while maintaining PyTorch's autograd compatibility.
Key Capabilities
torch.nn.Module
to optimized DaCe SDFGsCore Architecture
Integration Flow:
Dispatcher Strategies:
cpp_torch_extension.py
): Native PyTorch operator with autogradctypes_module.py
): Pure Python dispatcherZero-Copy Memory Sharing:
Key Files
dispatchers/cpp_torch_extension.py
dispatchers/ctypes_module.py
dlpack.py
environments/pytorch_env.py
How Components Work Together
Example: Training a PyTorch Model with DaCe
What Happens Internally:
Data Flow
Testing Strategy
Test Organization
Test Coverage
Running Tests
Known Limitations and Future Work
Current Limitations
Documentation
Each component has detailed design documentation:
dace/autodiff/autodiff.md
- Complete AD system designdace/libraries/onnx/onnx.md
- ONNX integration architecturedace/libraries/torch/torch.md
- PyTorch integration detailsThese documents provide:
Impact on DaCe
Code Additions
Dependencies
New dependencies (already in
setup.py
):onnx
- ONNX model formatonnxsim
- ONNX graph simplificationtorch
- PyTorch framework (optional)protobuf
- Protocol buffers (for ONNX)jax
- For gradient numerical validation tests-
transformers
- For testing the Pytorch/ONNX frontendsefficientnet_pytorch
- For testing EfficientNet