Hacker News new | ask | show | jobs
by natly 1461 days ago
Wow the source code is kind of blowing my mind. I had no idea this was possible (only in theory).

  import * as torch from "./torch.mjs";

  ...

  const w0 = torch.tensor(weights["conv1.0.weight"]);
  const b0 = torch.tensor(weights["conv1.0.bias"]);
  const w1 = torch.tensor(weights["conv2.0.weight"]);
  const b1 = torch.tensor(weights["conv2.0.bias"]);
  const lw = torch.tensor(weights["out.weight"]);
  const lb = torch.tensor(weights["out.bias"]);

  const convs = nn.Sequential(
    nn.Conv2d(w0, b0, 1, 2),
    nn.MaxPool2d(2),
    nn.ReLU(),
    nn.Conv2d(w1, b1, 1, 2),
    nn.MaxPool2d(2),
    nn.ReLU()
  );
  ... 
Looks like near identical python torch code except apparantely running in local js!
1 comments

this is actually a brand new proposal! If you like it or have any comments, you can find more information here: https://dev-discuss.pytorch.org/t/proposal-torch-js-a-javasc...