transformers.js icon indicating copy to clipboard operation
transformers.js copied to clipboard

Cannot import PretrainedModelOptions (or quantization data types) in typescript

Open jens-f opened this issue 1 year ago • 2 comments

System Info

Transformers.js 3.0.1 running in node 18 using CommonJS

Environment/Platform

  • [ ] Website/web-app
  • [ ] Browser extension
  • [X] Server-side (e.g., Node.js, Deno, Bun)
  • [ ] Desktop app (e.g., Electron)
  • [ ] Other (e.g., VSCode extension)

Description

When trying to import the PretrainedModelOptions type in my typescript application, I'm getting this error message:

'"@huggingface/transformers"' has no exported member named 'PretrainedModelOptions'. Did you mean 'PretrainedOptions'?

I'm getting a similar issue when trying to import the quantization data type that is mentioned in PretrainedModelOptions, (the datatype that contains e.g. q8).

The problem seems to be that neither types/utils/hub.d.ts nor types/utils/dtypes.d.ts are exported through types/transformers.d.ts

Reproduction

Using this statement:

import { PretrainedModelOptions } from '@huggingface/transformers';

results in the error message.

jens-f avatar Oct 28 '24 17:10 jens-f

@jens-ghc Funny I was just about to open this bug myself when I saw you had opened it just a few hours ago :)

At least a simple

import {
  pipeline,
  type PipelineType,
  // @ts-ignore temporary "fix"
  type PretrainedModelOptions,
  //...
} from '@huggingface/transformers';

Lets you work around it for now. Specifying the dtype via e.g.

const model = await pipeline(
  'image-feature-extraction',
  'Xenova/clip-vit-large-patch14-336',
  { dtype: 'fp16' }
)

still works as expected.

pachacamac avatar Oct 29 '24 01:10 pachacamac

Does that not just mean that PretrainedModelOptions = any ?

The problem is that tsc obeys some JSDoc conventions which does not allow SomeThing1 & SomeThing2 due to closure compiler stuff back in the day.

The codebase would need to be in TypeScript.

sroussey avatar Feb 14 '25 19:02 sroussey