huggingface / transformers.js

State-of-the-art Machine Learning for the web. Run 🤗 Transformers directly in your browser, with no need for a server!
https://huggingface.co/docs/transformers.js
Apache License 2.0
11.86k stars 747 forks source link

Cannot import PretrainedModelOptions (or quantization data types) in typescript #998

Open jens-ghc opened 1 week ago

jens-ghc commented 1 week ago

System Info

Transformers.js 3.0.1 running in node 18 using CommonJS

Environment/Platform

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.

pachacamac commented 1 week ago

@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.