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

Torch Backend in Transpiler #28860

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Torch Backend in Transpiler #28860

wants to merge 1 commit into from

Conversation

yugborana
Copy link

PR Description

Related Issue

#28848

Checklist

  • Did you add a function?
  • Did you add the tests?
  • Did you run your tests and are your tests passing?
  • Did pre-commit not fail on any check?
  • Did you follow the steps we provided?

@yugborana
Copy link
Author

@Sam-Armstrong @YushaArif99 Good Afternoon. Would like to request for a review?

Copy link
Contributor

@Sam-Armstrong Sam-Armstrong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yugborana Thanks for making the PR!

Looks like there's a few more things that will need changing before this works correctly. For example, you'll need to add torch as one of the SUPPORTED_S2S_TARGETS in ivy/transpiler/main_config.py.

I'd recommend using the following minimal example to check your solution is working correctly:

import kornia
import torch
import ivy

new_kornia = ivy.transpile(kornia, target="torch", reuse_existing=False)
rgb_image = torch.randn((1, 3, 224, 224))
gray_image = new_kornia.color.rgb_to_grayscale(rgb_image)

You can see this currently fails with the error ivy.transpiler.exceptions.exceptions.InvalidTargetException: 'target' must be one of ['tensorflow', 'jax', 'numpy', 'ivy', 'torch_frontend']. - but it looks like there are still other problems after fixing this.

@yugborana
Copy link
Author

yugborana commented Mar 24, 2025

@Sam-Armstrong Thanks for your time and guidance. I have changed the targets list.

File "c:\Users\dell\ivy\test.py", line 7, in
gray_image = new_kornia.color.rgb_to_grayscale(rgb_image)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\dell\ivy\ivy\transpiler\main.py", line 375, in wrapper
callable_obj = transpile(
^^^^^^^^^^
File "c:\Users\dell\ivy\ivy\transpiler\main.py", line 772, in transpile
return translate(
^^^^^^^^^^
File "c:\Users\dell\ivy\ivy\transpiler\main.py", line 725, in translate
raise e
File "c:\Users\dell\ivy\ivy\transpiler\main.py", line 708, in translate
translated_object = translators_container.run_translators(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\dell\ivy\ivy\transpiler\translators_container.py", line 58, in run_translators
object = self.translators[-1].translate(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\dell\ivy\ivy\transpiler\translations\translator.py", line 402, in translate
object_like = self._setup_translation(object=object)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "c:\Users\dell\ivy\ivy\transpiler\translations\translator.py", line 115, in _setup_translation
self._output_dir = create_output_dir(
^^^^^^^^^^^^^^^^^^
File "c:\Users\dell\ivy\ivy\transpiler\utils\source_utils.py", line 247, in create_output_dir
_maybe_create_stateful_layers_module(NAME_GENERATOR.target, output_dir)
File "c:\Users\dell\ivy\ivy\transpiler\utils\source_utils.py", line 86, in _maybe_create_stateful_layers_module
stateful_file = os.path.join(output_dir, f"{module_name}.py")
^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'module_name' where it is not associated with a value

Yeah many errors occurring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants