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 simple JS backend #2072

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

zamfofex
Copy link

@zamfofex zamfofex commented Oct 6, 2024

I was told this might be desirable. A couple things to note:

  • I wish to be able to publish this as a package to npm eventually. (I hope this can be allowed!)
  • I have only tried this with Emscripten v3.1.57, see: Compiled code using pthreads breaks Vite bundler emscripten-core/emscripten#22394
  • If there is anything I can improve, I’d love to try to!
  • I set this as a draft pull request because I think the documentation could be improved, and also because I have set up some ORT‐web compatibility changes very directly, whereas they should probably be conditional.
  • This only works well in browsers with WebGPU enabled (and in computers with a decent GPU), so this is currently fairly niche.

If anyone has any thoughts on whether this is warranted, I’d love to know! (Do let me know what you think!)

Some more technical details: This works by converting an Lc0 network to ONNX format (with leela2onnx) and then using the ORT‐web APIs to allow Lc0 to interface with the network through JavaScript.

@@ -45,7 +45,7 @@ struct WeightsToOnnxConverterOptions {
std::string output_mlh = "/output/mlh";
int batch_size = -1;
int opset = 17;
bool alt_mish = false; // Use "Mish" approximation (fp32 only).
bool alt_mish = true; // Use "Mish" approximation (fp32 only).
Copy link
Member

Choose a reason for hiding this comment

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

This is not the way to do it, add a flag in leela2onnx.cc.

return PopulateStdNodeFields(node, name, input, "Selu");
auto out = PopulateStdNodeFields(node, name + "/elu", input, "Elu");
AddFloatAttribute(node, "alpha", 1.0507);
return Mul(name, out, FloatOnnxConst({1.67326}, {1}));
}
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest using a flag, but probably doesn't make a difference. Better keep the Selu operator unchanged and add an Elu one, then make the change in the converter (with a comment).

#else

bool GetLine(std::string& line) {
return std::getline(std::cin, line);
Copy link
Member

Choose a reason for hiding this comment

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

This breaks the build, I think one solution is to change it to return !!std::getline(std::cin, line);.

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