esm-dev / esm.sh

The no-build CDN for modern web development.
https://esm.sh
MIT License
3.15k stars 151 forks source link

Failed to import - @xenova/transformers #707

Open marcfrankel opened 1 year ago

marcfrankel commented 1 year ago

Failing module

import { env, pipeline } from "@xenova/transformers";

Error message

After running deno run I got this:

[Error] An error occurred during model execution: "TypeError: __Process$.hrtime is not a function".

[Error] Inputs given to model: {
  input_ids: n {
    dims: [ 1, 7 ],
    type: "int64",
    data: BigInt64Array(7) [
       101n, 7592n,
      2088n, 1045n,
      2293n, 2017n,
       102n
    ],
    size: 7
  },
  attention_mask: n {
    dims: [ 1, 7 ],
    type: "int64",
    data: BigInt64Array(7) [
      1n, 1n, 1n, 1n,
      1n, 1n, 1n
    ],
    size: 7
  },
  token_type_ids: n {
    dims: [ 1, 7 ],
    type: "int64",
    data: BigInt64Array(7) [
      0n, 0n, 0n, 0n,
      0n, 0n, 0n
    ],
    size: 7
  }
}

[Error] TypeError: __Process$.hrtime is not a function
    at https://esm.sh/v131/onnxruntime-web@1.14.0/esnext/onnxruntime-web.mjs:9:4996
    at <anonymous> (wasm://wasm/02633f4a:1:3401388)
    at <anonymous> (wasm://wasm/02633f4a:1:8565720)
    at <anonymous> (wasm://wasm/02633f4a:1:8428626)
    at W (https://esm.sh/v131/onnxruntime-web@1.14.0/esnext/onnxruntime-web.mjs:9:8426)
    at <anonymous> (wasm://wasm/02633f4a:1:3322223)
    at <anonymous> (wasm://wasm/02633f4a:1:343366)
    at <anonymous> (wasm://wasm/02633f4a:1:1344502)
    at <anonymous> (wasm://wasm/02633f4a:1:8428507)
    at a.dynCall_viiijjjii (https://esm.sh/v131/onnxruntime-web@1.14.0/esnext/onnxruntime-web.mjs:9:15057)

Additional info

This started from trying to change the Deno import URL from jsdilvr.net to esm.sh since the jsdilvr on doesn't supply types, but esm.sh does. Code is from https://supabase.com/docs/guides/ai/quickstarts/generate-text-embeddings. They announced this as a new feature during their launch week last week.

From my research is seems to have to do with the underlying package onnxruntime-web vs onnxruntime-node

Results of deno info

deno info https://esm.sh/@xenova/transformers                                                                                        ─╯
local: /Users/[redcated]/Library/Caches/deno/deps/https/esm.sh/3445bf0cd1fc558e8166b82033fdeab338a0b1a611344583aa08c5428d12d25b
type: JavaScript
dependencies: 22 unique
size: 885.64KB

https://esm.sh/@xenova/transformers@2.5.2 (304B)
├─┬ https://esm.sh/v131/@xenova/transformers@2.5.2/types/transformers.d.ts (383B)
│ ├─┬ https://esm.sh/v131/@xenova/transformers@2.5.2/types/pipelines.d.ts (34.71KB)
│ │ ├─┬ https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/tensor.d.ts (9.5KB)
│ │ │ └── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/maths.d.ts (11.15KB)
│ │ ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/hub.d.ts (7.87KB)
│ │ ├─┬ https://esm.sh/v131/@xenova/transformers@2.5.2/types/models.d.ts (71.73KB)
│ │ │ ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/transformers.d.ts *
│ │ │ ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/hub.d.ts *
│ │ │ ├─┬ https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/generation.d.ts (23.59KB)
│ │ │ │ └── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/tensor.d.ts *
│ │ │ └── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/tensor.d.ts *
│ │ ├─┬ https://esm.sh/v131/@xenova/transformers@2.5.2/types/tokenizers.d.ts (26.56KB)
│ │ │ ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/hub.d.ts *
│ │ │ └── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/tensor.d.ts *
│ │ └─┬ https://esm.sh/v131/@xenova/transformers@2.5.2/types/processors.d.ts (16.77KB)
│ │   ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/hub.d.ts *
│ │   ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/image.d.ts (3.86KB)
│ │   └── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/tensor.d.ts *
│ ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/env.d.ts (943B)
│ ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/models.d.ts *
│ ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/tokenizers.d.ts *
│ ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/processors.d.ts *
│ ├─┬ https://esm.sh/v131/@xenova/transformers@2.5.2/types/configs.d.ts (2.14KB)
│ │ └── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/hub.d.ts *
│ ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/audio.d.ts (905B)
│ ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/image.d.ts *
│ ├── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/tensor.d.ts *
│ └── https://esm.sh/v131/@xenova/transformers@2.5.2/types/utils/maths.d.ts *
├── https://esm.sh/v131/onnxruntime-node@1.14.0/denonext/onnxruntime-node.mjs (loading error)
├─┬ https://esm.sh/v131/onnxruntime-web@1.14.0/denonext/onnxruntime-web.mjs (532.48KB)
│ ├── node:process (unknown)
│ └── https://esm.sh/v131/onnxruntime-common@1.14.0/denonext/onnxruntime-common.mjs (11.58KB)
├── https://esm.sh/v131/sharp@0.32.4/denonext/sharp.mjs (loading error)
└─┬ https://esm.sh/v131/@xenova/transformers@2.5.2/denonext/transformers.mjs (131.24KB)
  ├── node:process *
  ├── node:buffer (unknown)
  ├── node:fs (unknown)
  ├── node:path (unknown)
  ├── node:stream/web (unknown)
  ├── node:url (unknown)
  ├── https://esm.sh/v131/onnxruntime-node@1.14.0/denonext/onnxruntime-node.mjs (loading error)
  ├── https://esm.sh/v131/onnxruntime-web@1.14.0/denonext/onnxruntime-web.mjs *
  └── https://esm.sh/v131/sharp@0.32.4/denonext/sharp.mjs (loading error)
ije commented 1 year ago

Thanks, just had a look and found some informations i can tell:

  1. deno info https://esm.sh/@xenova/transformers use the denonext target that includes urls https://esm.sh/v131/sharp@0.32.4/denonext/sharp.mjs and https://esm.sh/v131/onnxruntime-node@1.14.0/denonext/onnxruntime-node.mjs that are trying to import *.node( node native module) this is not been supported by esm.sh in Deno. (this is one of the reasons why deno starts to support npm: specifier instead of CDN)
  2. deno info https://esm.sh/@xenova/transformers?target=esnext use onnxruntime-web that meets the "TypeError: __Process$.hrtime is not a function" error.

i'm going to add the hrtime method for the process polyfill may fix situation 2, for situation 1 currently there is nothing i can do.

marcfrankel commented 1 year ago

Thanks for checking this out for me so fast. If I'm understanding you then you're saying to wait until you add the polyfill for hrtime and then option 2 may work?

ije commented 1 year ago

Thanks for checking this out for me so fast. If I'm understanding you then you're saying to wait until you add the polyfill for hrtime and then option 2 may work?

right

ije commented 1 year ago

for now if you just want the types, you can use the deno-types:

// @deno-types="https://esm.sh/v131/@xenova/transformers@2.5.2/types/transformers.d.ts"
import { env, pipeline } from "https://unpkg.com/@xenova/transformers@2.5.2";
marcfrankel commented 1 year ago

for now if you just want the types, you can use the deno-types:

// @deno-types="https://esm.sh/v131/@xenova/transformers@2.5.2/types/transformers.d.ts"
import { env, pipeline } from "https://unpkg.com/@xenova/transformers@2.5.2";

Oh my god you're my hero! I tried to get this working for like three hours yesterday!! Using that setup does give me both types and a working form of the package