-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
Description:
The current implementation of ivy.transpile
supports "torch"
as the sole source
argument. This allows transpiling PyTorch functions or classes to target frameworks like TensorFlow, JAX, or NumPy. This task aims to extend the functionality by adding Numpy as a valid source
, enabling transpilation of Numpy code to other frameworks via Ivy's intermediate representation.
For example, after completing this task, we should be able to transpile Numpy code using:
ivy.transpile(func, source="numpy", target="jax")
Goals:
The main objective is to implement the first two stages of the transpilation pipeline for Numpy:
- Lower Numpy code to Ivy’s Numpy Frontend IR.
- Transform the Numpy Frontend IR to Ivy’s core representation.
Once these stages are complete, the rest of the pipeline can be reused to target other frameworks like JAX, PyTorch, or TensorFlow. The steps would look as follows:
source='numpy' → target='numpy_frontend'
source='numpy_frontend' → target='ivy'
source='ivy' → target='jax'/'torch'/etc.
This mirrors the existing pipeline for PyTorch:
source='torch' → target='torch_frontend'
source='torch_frontend' → target='ivy'
source='ivy' → target='jax'/'numpy'/etc.
Key Tasks:
-
Add Native Framework-Specific Implementations for Core Transformation Passes:
- For example, implement the
native_numpy_recursive_transformer.py
for traversing and transforming Numpy native source code. - Use
native_torch_recursive_transformer.py
as a reference (example here)
- For example, implement the
-
Define the Transformation Pipeline for Numpy to Numpy Frontend IR:
- Create a new pipeline in
source_to_frontend_translator_config.py
to handle the stagesource='numpy', target='numpy_frontend'
(example here).
- Create a new pipeline in
-
Define the Transformation Pipeline for Numpy Frontend IR to Ivy:
- Add another pipeline in
frontend_to_ivy_translator_config.py
to handle the stagesource='numpy_frontend', target='ivy'
(example here).
- Add another pipeline in
-
Add Stateful Classes for Numpy
- NOTE: Numpy does not natively support any stateful classes so this step can be skipped.
-
Understand and Leverage Reusability:
- Explore reusable components in the existing PyTorch pipeline, especially for AST transformers and configuration management.
Testing:
- Familiarize yourself with the transpilation flow by exploring transpiler tests
- Add appropriate tests to validate Numpy source transpilation at each stage of the pipeline.
Additional Notes:
- Keep in mind the modular and extensible design of the transpiler, ensuring that the new implementation integrates smoothly into the existing architecture.