burn icon indicating copy to clipboard operation
burn copied to clipboard

Cross-Platform Integration using `xtask-wasm`

Open antimora opened this issue 1 year ago • 10 comments

Description:

As we aim to make our project more cross-platform compatible, leveraging xtask-wasm appears to be a viable solution.

Objectives:

  1. Translate existing scripts to their xtask-wasm equivalents:
    • examples/image-classification-web/build-for-web.sh
    • examples/image-classification-web/run-server.sh
    • examples/mnist-inference-web/build-for-web.sh
    • examples/mnist-inference-web/run-server.sh

About xtask-wasm:

Features of xtask-wasm include:

  • Dist: Ability to generate a distributed package for Wasm.
  • Watch: Automatically re-run a given command when changes are detected (this leverages xtask-watch).
  • DevServer: Serve the project at a designated IP address.

Reason for Integration:

The primary incentive for integrating xtask-wasm is its cross-platform capabilities. Ensuring our project's scripts are compatible across different platforms will significantly boost accessibility and usability.

We would appreciate insights, suggestions, or any potential challenges foreseen in this transition.

antimora avatar Oct 06 '23 15:10 antimora

@Luni-4, wanna give a try? =)

antimora avatar Oct 06 '23 15:10 antimora

If it's not urgent, feel free to assign to me this task :)

Luni-4 avatar Oct 06 '23 15:10 Luni-4

No, it's not urgent. I just could not complete it in time for the example. I'll be traveling soon so I can't finish it.

antimora avatar Oct 06 '23 15:10 antimora

@antimora

We can rewrite the https://github.com/burn-rs/burn/blob/main/examples/image-classification-web/https_server.py in https://github.com/tokio-rs/axum in order to simplify the xtask-wasm transition. Are you willing to do that?

Luni-4 avatar Nov 06 '23 10:11 Luni-4

@antimora

We can rewrite the https://github.com/burn-rs/burn/blob/main/examples/image-classification-web/https_server.py in https://github.com/tokio-rs/axum in order to simplify the xtask-wasm transition. Are you willing to do that?

In the end, I think you might end up recreating xtask-wasm. It is better to give a try to use the lib. If we can get it working, the same solution can be applied to other projects (outside burn), including mnist digits.

antimora avatar Nov 06 '23 14:11 antimora

@antimora We can rewrite the https://github.com/burn-rs/burn/blob/main/examples/image-classification-web/https_server.py in https://github.com/tokio-rs/axum in order to simplify the xtask-wasm transition. Are you willing to do that?

In the end, I think you might end up recreating xtask-wasm. It is better to give a try to use the lib. If we can get it working, the same solution can be applied to other projects (outside burn), including mnist digits.

The Start command runs what we have previously defined in Dist. In our case, building the web app and running the server are two distinct phases. So I suppose we have to implement a server and then run it, but ok, let me try to use the default options and see if we will obtain the same results

Luni-4 avatar Nov 06 '23 15:11 Luni-4

Related: https://github.com/burn-rs/burn/issues/917

antimora avatar Nov 13 '23 18:11 antimora

Another idea is to do something similar to this PR to wasm_bindgen and use Python. Sure we could remove the Python dependency from examples/mnist-inference-web, but we can't remove it from burn-dataset or examples/guide. Should we move from a solid and popular dependency like Python to such a small library? Python is already incredibly popular in machine learning, and I'm not sure having people read/grok/debug xtask-wasm is a good use of time when they're just trying to follow an example. Related. Also, iteration times suffer since Python is a scripting language and WASM is not.

(Advanced apologies to Luni-4 for potentially nuking all your work 😬)

AlexErrant avatar Nov 30 '23 03:11 AlexErrant

No, we need to stick with xtask because it is most portable. We have image classifier that does not use python. And I predict we might want to remove python dependency entirely in the future.

antimora avatar Nov 30 '23 03:11 antimora

I think having minimal dependency for the build process is very valuable and will contribute to a simpler setup. We use Python in burn-dataset to download data from Huggingface, and it often causes problems, but we don't have any other viable alternative for now.

nathanielsimard avatar Nov 30 '23 20:11 nathanielsimard

@Luni-4 has found this build tool we should look into: https://github.com/trunk-rs/trunk

Here is their vanilla js example: https://github.com/trunk-rs/trunk/tree/main/examples/vanilla

antimora avatar Jan 30 '24 16:01 antimora

The documentation and some information are here: https://trunkrs.dev/

Luni-4 avatar Jan 30 '24 16:01 Luni-4