-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
Description:
The current implementation of ivy.transpile supports "jax","numpy" and "tensorflow" as valid target argument. This allows transpiling framework-specific code such as PyTorch functions or classes to target frameworks like TensorFlow, JAX, or NumPy. This task aims to extend the functionality by adding Pytorch as a valid target, enabling code to be transpiled to Pytorch.
For example, after completing this task, we should be able to transpile TensorFlow code using:
ivy.transpile(func, source="tensorflow", target="torch")Goals:
The main objective is to implement the final stage of the transpilation pipeline:
- Lower Ivy IR representation to native Pytorch code.
Once this stage is complete, the rest of the pipeline can be reused to target other frameworks like JAX, PyTorch, or NumPy. The steps would look as follows:
source='tensorflow' → target='tensorflow_frontend'
source='tensorflow_frontend' → target='ivy'
source='ivy' → target='torch'
This mirrors the existing pipeline for eg: PyTorch -> TF:
source='torch' → target='torch_frontend'
source='torch_frontend' → target='ivy'
source='ivy' → target='tensorflow'
Key Tasks:
- Add Native Framework-Specific Implementations for Core Transformation Passes:
- For example, implement the
ivy_to_torch_postprocessing_transformer.pyfor doing postprocessing on the Ivy code when lowering it to Pytorch (eg: mapping ivy dtypes (eg:ivy.float32) to torch dtypes(torch.float32) - Use
ivy_to_jax_postprocessing_transformer.pyas a reference (example here)
- For example, implement the
2 Define the Transformation Pipeline for Ivy IR to Torch
- Create a new pipeline in
ivy_to_source_translator_config.pyto handle the stagesource='ivy', target='torch'(example here).
-
Add Stateful Classes for
torch.nnAPIs:- Add a subclass implementation for
torch.nn.Modulethat exposes the similar interface as that ofivy.Module. - Reference the existing implementation for
keras.Modelornnx.Module(example 1) (example 2) - This allows for sequential lowering for eg:
keras.Model → (frontend keras.Model) → ivy.Module → nn.Module
- Add a subclass implementation for
-
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 Pytorch target transpilation at the final 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.