Skip to content
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

Add TensorFlow Frontend Support to Ivy Transpiler #28845

Open
YushaArif99 opened this issue Dec 17, 2024 · 0 comments
Open

Add TensorFlow Frontend Support to Ivy Transpiler #28845

YushaArif99 opened this issue Dec 17, 2024 · 0 comments
Labels
TensorFlow Frontend Developing the TensorFlow Frontend, checklist triggered by commenting add_frontend_checklist ToDo A ToDo list of tasks Transpiler Anything related to transpiling

Comments

@YushaArif99
Copy link
Contributor

YushaArif99 commented Dec 17, 2024

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 TensorFlow as a valid source, enabling transpilation of TensorFlow code to other frameworks via Ivy's intermediate representation.

For example, after completing this task, we should be able to transpile TensorFlow code using:

ivy.transpile(func, source="tensorflow", target="jax")

Goals:

The main objective is to implement the first two stages of the transpilation pipeline for TensorFlow:

  1. Lower TensorFlow code to Ivy’s TensorFlow Frontend IR.
  2. Transform the TensorFlow 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 NumPy. The steps would look as follows:

source='tensorflow' → target='tensorflow_frontend'  
source='tensorflow_frontend' → target='ivy'  
source='ivy' → target='jax'/'numpy'/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:

  1. Add Native Framework-Specific Implementations for Core Transformation Passes:

    • For example, implement the native_tf_recursive_transformer.py for traversing and transforming TensorFlow native source code.
    • Use native_torch_recursive_transformer.py as a reference (example here)
  2. Define the Transformation Pipeline for TensorFlow to TensorFlow Frontend IR:

    • Create a new pipeline in source_to_frontend_translator_config.py to handle the stage source='tensorflow', target='tensorflow_frontend' (example here).
  3. Define the Transformation Pipeline for TensorFlow Frontend IR to Ivy:

    • Add another pipeline in frontend_to_ivy_translator_config.py to handle the stage source='tensorflow_frontend', target='ivy' (example here).
  4. Add Stateful Classes for TensorFlow's Keras APIs:

    • Implement stateful classes for keras.Layer and keras.Model APIs that inherit from ivy.Module.
    • Reference the existing implementation for PyTorch's nn.Module (example here)
    • This allows for sequential lowering:
      keras.Model → (frontend keras.Model) → ivy.Module → (target keras.Model/keras.Layer)
      
  5. 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 TensorFlow 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.
  • Be prepared for nuances or intricacies in TensorFlow's API, especially with keras layers and models.
@YushaArif99 YushaArif99 added TensorFlow Frontend Developing the TensorFlow Frontend, checklist triggered by commenting add_frontend_checklist ToDo A ToDo list of tasks Transpiler Anything related to transpiling labels Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TensorFlow Frontend Developing the TensorFlow Frontend, checklist triggered by commenting add_frontend_checklist ToDo A ToDo list of tasks Transpiler Anything related to transpiling
Projects
None yet
Development

No branches or pull requests

2 participants