Skip to content

fix: correct type definitions for AutoTokenizer and AutoModelForCausalLM#1499

Closed
VedantMadane wants to merge 1 commit intohuggingface:mainfrom
VedantMadane:fix/type-definitions-auto-classes
Closed

fix: correct type definitions for AutoTokenizer and AutoModelForCausalLM#1499
VedantMadane wants to merge 1 commit intohuggingface:mainfrom
VedantMadane:fix/type-definitions-auto-classes

Conversation

@VedantMadane
Copy link

Description

This PR fixes incorrect TypeScript type definitions for AutoTokenizer and AutoModelForCausalLM.

Fixes #1495

Changes

src/models.js

  • PretrainedMixin.from_pretrained: Replaced @type {typeof PreTrainedModel.from_pretrained} with full JSDoc documentation including proper parameter and return type annotations
  • AutoModelForCausalLM: Added explicit from_pretrained override with proper JSDoc to ensure TypeScript correctly types the return value

src/tokenizers.js

  • PreTrainedTokenizer.from_pretrained: Changed @param {PretrainedTokenizerOptions} options to @param {PretrainedTokenizerOptions} [options] to correctly mark as optional
  • AutoTokenizer.from_pretrained: Same fix - marked options parameter as optional

Type Generation

After running npm run typegen, the generated .d.ts files now correctly show:

  • from_pretrained methods with optional options parameter (?)
  • Proper return types (Promise<PreTrainedTokenizer> and Promise<PreTrainedModel>)

Testing

Created a TypeScript test file to validate the fixes - compilation succeeded with no errors.

@VedantMadane
Copy link
Author

Friendly ping - is there anything I can do to help move this PR forward? Happy to make any changes if needed.

@VedantMadane VedantMadane force-pushed the fix/type-definitions-auto-classes branch from 964bb1b to 5fff56a Compare February 10, 2026 13:01
@nico-martin
Copy link
Collaborator

Hi @VedantMadane, we just merged our v4 branch into main, which brings a lot of type improvements. Could you check if your changes are still needed?

@nico-martin nico-martin self-assigned this Feb 13, 2026
@VedantMadane VedantMadane force-pushed the fix/type-definitions-auto-classes branch from 5fff56a to 3912f6e Compare February 21, 2026 05:21
@VedantMadane
Copy link
Author

Thanks for the heads-up! I've checked the latest \main\ branch.

It looks like the changes to \AutoTokenizer.from_pretrained\ and \PreTrainedTokenizer.from_pretrained\ (making the \options\ parameter optional) are already included.

However, the explicit \ rom_pretrained\ override for \AutoModelForCausalLM\ with the JSDoc for proper TypeScript return type inference is still missing. This change is still needed to ensure correct type definitions are generated.

I've updated this PR to only include the necessary changes for \AutoModelForCausalLM\ by rebasing onto the latest \main.

@xenova xenova closed this Feb 23, 2026
@xenova
Copy link
Collaborator

xenova commented Feb 23, 2026

Closing as changes are no longer valid (as of v4 update) and #1495 is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect Type Definitions for AutoTokenizer and AutoModelForCausalLM

3 participants