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

[Web] #22848

Open
catsandsoup32 opened this issue Nov 15, 2024 · 0 comments
Open

[Web] #22848

catsandsoup32 opened this issue Nov 15, 2024 · 0 comments
Labels
ep:Xnnpack issues related to XNNPACK EP platform:web issues related to ONNX Runtime web; typically submitted using template

Comments

@catsandsoup32
Copy link

catsandsoup32 commented Nov 15, 2024

Describe the issue

When exporting my model from torch as below and testing ORT in python, everything is fine, but I get an uncaught error when trying to run the model in ORT web in a chrome extension environment.

full_model = Model_1(vocab_size=217, d_model=256, nhead=8, dim_FF=1024, dropout=0, num_layers=3)
full_model.load_state_dict(torch.load('runs/Exp8E8End_Acc=0.6702922582626343.pt', map_location = device, weights_only=True))
full_model.eval()
seq_len = Dim("seq_len", min=1, max=200)
torch.onnx.export(
    full_model.to(device), 
    (torch.randn(1,3,384,512).to(device),
     torch.ones([1, 1], dtype=torch.long).to(device),
     torch.triu(torch.ones(1, 1) * float("-inf"), diagonal=1).to(device)
    ),
    "model_2.onnx",
    export_params = True,
    input_names = ["src", "tgt", "tgt_mask"],
    output_names = ["output1"],
    dynamo = True,
    dynamic_shapes = {"src": None, "tgt": {1: seq_len}, "tgt_mask": {0: seq_len, 1:seq_len}},
    report = True,
    optimize = True,
    verify = True
)

The markdown torch export success report
My project directory structure

Thank you in advance for the help, any insight into what's going on would be great.

To reproduce

My project directory structure

{
  "manifest_version": 3,
  "name": "TeXan",
  "version": "0.1",
  "description": "Handwriting to LaTeX",

  "icons": {
      "16": "icons/icon-16.png",
      "32": "icons/icon-32.png",
      "48": "icons/icon-48.png",
      "128": "icons/icon-128.png"
  },
  "action": {
    "default_title": "TeXan",
    "default_popup": "popup.html",
    "default_icon": {
        "16": "icons/icon-16.png",
        "32": "icons/icon-32.png",
        "48": "icons/icon-48.png",
        "128": "icons/icon-128.png"
    }
  },
  "sandbox": {
    "pages": ["popup.html"]
  },
  "web_accessible_resources": [
    {
      "resources": ["popup.html"],
      "matches": ["<all_urls>"]
    }
  ],
  "content_security_policy": {
    "sandbox": "sandbox allow-scripts; script-src 'unsafe-eval';" 
  }
// file test.js, I installed ORT through npm

async function testInference() {
    const session = await ort.InferenceSession.create('model_2.onnx');

    const src_array = new Float32Array(3*384*512); 
    const src_tensor = new ort.Tensor( 'float32', src_array, [1, 3, 384, 512] );
    
    const tgt_array = new BigInt64Array(2);
    const tgt_tensor = new ort.Tensor('int64', tgt_array, [1, 2] );
    
    const tgt_mask_array = new Float32Array(4);
    const tgt_mask_tensor = new ort.Tensor( 'float32', tgt_mask_array, [2, 2] );

    const test_output = await session.run(
        {src: src_tensor, tgt: tgt_tensor, tgt_mask: tgt_mask_tensor}
    );

}

testInference();

model_2.onnx.data file
model_2.onnx file

Urgency

No response

ONNX Runtime Installation

Released Package

ONNX Runtime Version or Commit ID

1.20.0

Execution Provider

'xnnpack' (WebAssembly XNNPACK), 'wasm'/'cpu' (WebAssembly CPU)

@catsandsoup32 catsandsoup32 added the platform:web issues related to ONNX Runtime web; typically submitted using template label Nov 15, 2024
@github-actions github-actions bot added the ep:Xnnpack issues related to XNNPACK EP label Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ep:Xnnpack issues related to XNNPACK EP platform:web issues related to ONNX Runtime web; typically submitted using template
Projects
None yet
Development

No branches or pull requests

1 participant