Cannot import PretrainedModelOptions (or quantization data types) in typescript
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-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.
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.