esm.sh icon indicating copy to clipboard operation
esm.sh copied to clipboard

Failed to import - @xenova/transformers

Open marcfrankel opened this issue 2 years ago • 5 comments

Failing module

  • GitHub: https://github.com/xenova/transformers.js
  • npm: https://www.npmjs.com/package/@xenova/transformers
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/[email protected]/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/[email protected]/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/[email protected]/esnext/onnxruntime-web.mjs:9:15057)

Additional info

  • esm.sh version: https://esm.sh/@xenova/transformers
  • Deno version: 1.36.0

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/[email protected] (304B)
├─┬ https://esm.sh/v131/@xenova/[email protected]/types/transformers.d.ts (383B)
│ ├─┬ https://esm.sh/v131/@xenova/[email protected]/types/pipelines.d.ts (34.71KB)
│ │ ├─┬ https://esm.sh/v131/@xenova/[email protected]/types/utils/tensor.d.ts (9.5KB)
│ │ │ └── https://esm.sh/v131/@xenova/[email protected]/types/utils/maths.d.ts (11.15KB)
│ │ ├── https://esm.sh/v131/@xenova/[email protected]/types/utils/hub.d.ts (7.87KB)
│ │ ├─┬ https://esm.sh/v131/@xenova/[email protected]/types/models.d.ts (71.73KB)
│ │ │ ├── https://esm.sh/v131/@xenova/[email protected]/types/transformers.d.ts *
│ │ │ ├── https://esm.sh/v131/@xenova/[email protected]/types/utils/hub.d.ts *
│ │ │ ├─┬ https://esm.sh/v131/@xenova/[email protected]/types/utils/generation.d.ts (23.59KB)
│ │ │ │ └── https://esm.sh/v131/@xenova/[email protected]/types/utils/tensor.d.ts *
│ │ │ └── https://esm.sh/v131/@xenova/[email protected]/types/utils/tensor.d.ts *
│ │ ├─┬ https://esm.sh/v131/@xenova/[email protected]/types/tokenizers.d.ts (26.56KB)
│ │ │ ├── https://esm.sh/v131/@xenova/[email protected]/types/utils/hub.d.ts *
│ │ │ └── https://esm.sh/v131/@xenova/[email protected]/types/utils/tensor.d.ts *
│ │ └─┬ https://esm.sh/v131/@xenova/[email protected]/types/processors.d.ts (16.77KB)
│ │   ├── https://esm.sh/v131/@xenova/[email protected]/types/utils/hub.d.ts *
│ │   ├── https://esm.sh/v131/@xenova/[email protected]/types/utils/image.d.ts (3.86KB)
│ │   └── https://esm.sh/v131/@xenova/[email protected]/types/utils/tensor.d.ts *
│ ├── https://esm.sh/v131/@xenova/[email protected]/types/env.d.ts (943B)
│ ├── https://esm.sh/v131/@xenova/[email protected]/types/models.d.ts *
│ ├── https://esm.sh/v131/@xenova/[email protected]/types/tokenizers.d.ts *
│ ├── https://esm.sh/v131/@xenova/[email protected]/types/processors.d.ts *
│ ├─┬ https://esm.sh/v131/@xenova/[email protected]/types/configs.d.ts (2.14KB)
│ │ └── https://esm.sh/v131/@xenova/[email protected]/types/utils/hub.d.ts *
│ ├── https://esm.sh/v131/@xenova/[email protected]/types/utils/audio.d.ts (905B)
│ ├── https://esm.sh/v131/@xenova/[email protected]/types/utils/image.d.ts *
│ ├── https://esm.sh/v131/@xenova/[email protected]/types/utils/tensor.d.ts *
│ └── https://esm.sh/v131/@xenova/[email protected]/types/utils/maths.d.ts *
├── https://esm.sh/v131/[email protected]/denonext/onnxruntime-node.mjs (loading error)
├─┬ https://esm.sh/v131/[email protected]/denonext/onnxruntime-web.mjs (532.48KB)
│ ├── node:process (unknown)
│ └── https://esm.sh/v131/[email protected]/denonext/onnxruntime-common.mjs (11.58KB)
├── https://esm.sh/v131/[email protected]/denonext/sharp.mjs (loading error)
└─┬ https://esm.sh/v131/@xenova/[email protected]/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/[email protected]/denonext/onnxruntime-node.mjs (loading error)
  ├── https://esm.sh/v131/[email protected]/denonext/onnxruntime-web.mjs *
  └── https://esm.sh/v131/[email protected]/denonext/sharp.mjs (loading error)

marcfrankel avatar Aug 17 '23 16:08 marcfrankel

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/[email protected]/denonext/sharp.mjs and https://esm.sh/v131/[email protected]/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.

ije avatar Aug 17 '23 17:08 ije

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?

marcfrankel avatar Aug 17 '23 17:08 marcfrankel

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 avatar Aug 17 '23 17:08 ije

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

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

ije avatar Aug 17 '23 18:08 ije

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

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

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

marcfrankel avatar Aug 17 '23 18:08 marcfrankel