Skip to content

Add Pyodide implementation#117

Draft
veehz wants to merge 10 commits intosource-academy:mainfrom
veehz:pyodide-torch
Draft

Add Pyodide implementation#117
veehz wants to merge 10 commits intosource-academy:mainfrom
veehz:pyodide-torch

Conversation

@veehz
Copy link
Copy Markdown

@veehz veehz commented Mar 26, 2026

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces Pyodide, a Python distribution for the browser, to enable the execution of Python code directly within the application. A significant part of this integration involves creating a robust bridge between Python and a JavaScript-based PyTorch implementation, allowing users to write PyTorch-compatible Python code that leverages the underlying JavaScript library. This expands the platform's capabilities to support Python-based machine learning and data science workflows directly in the browser.

Highlights

  • Pyodide Integration: Integrated Pyodide to enable in-browser Python execution, expanding the platform's capabilities for Python-based workflows.
  • PyTorch-Python Bridge: Developed a comprehensive Python-JavaScript bridge (bridge.py) that mirrors the PyTorch API, allowing Python code to interact with an underlying JavaScript PyTorch implementation.
  • Smart Import Handling: Implemented an importAnalyzer to intelligently detect and rewrite PyTorch imports in Python code, ensuring seamless integration with the bridged PyTorch library.
  • Build and Test Configuration Updates: Updated build (Rollup) and test (Jest) configurations to properly handle Python files and the new Pyodide setup, including a custom transformer for .py files.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@veehz veehz force-pushed the pyodide-torch branch 2 times, most recently from 7edc67b to adc811e Compare March 26, 2026 09:12
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request integrates Pyodide to enable running Python code, specifically PyTorch, within the JavaScript environment. Key changes include adding pyodide and torch dependencies, configuring Rollup and Jest for Python file handling, and introducing a PyodideEvaluator to manage Pyodide execution. A Python bridge (bridge.py) is implemented to provide a PyTorch-compatible API over a JavaScript torch library, along with an importAnalyzer to rewrite torch imports and identify other modules for micropip installation. Review comments highlight a concern regarding the torch dependency being pulled from a custom, potentially unstable URL, recommending the use of officially published versions. A functional limitation in torch.cat is noted, as it currently only supports dim=0, suggesting either broader compatibility or clear documentation. Finally, the use of a dummy statement (_ = 0\n) in importAnalyzer.ts to satisfy the py-slang grammar is identified as a workaround that relies on internal parser details, with a recommendation for a more robust parsing solution.

Comment thread package.json Outdated
Comment on lines +64 to +65
"pyodide": "^0.29.3",
"torch": "https://pkg.pr.new/veehz/torch@297abf6",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The torch dependency is being pulled from a custom URL (https://pkg.pr.new/veehz/torch@297abf6). Relying on a specific, potentially temporary, branch or fork for a dependency can lead to instability, lack of updates, and security concerns. It's generally recommended to use officially published versions from a package registry (e.g., npm) or a stable, versioned release.

Comment thread src/pyodide/bridge.py Outdated
Comment thread src/pyodide/importAnalyzer.ts Outdated
Comment thread src/pyodide/importAnalyzer.ts
@martin-henz
Copy link
Copy Markdown
Member

Fixes #11

@veehz veehz force-pushed the pyodide-torch branch 2 times, most recently from 71fdabc to 9d86260 Compare March 29, 2026 06:09
@veehz veehz self-assigned this Mar 29, 2026
@veehz veehz force-pushed the pyodide-torch branch from 373a7a3 to cf388d2 Compare May 5, 2026 15:12
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