published fresh until

Transformers v4 to v5: how do I migrate loading and tokenizers?

Summary As of November 2026, migrate Transformers loading and tokenizers together: replace removed Auto classes, handle chat inputs as mappings, and explicitly test dtype and placement against your old lock. PyPI lists 5.24.0 (checked 2026-11-24).

Not for Hugging Face GGUF runtime crashes, see glm-5-3-flash-gguf-unknown-projector-glm5next-llama-cpp

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

What this thread does

The problem

Your agent updates a working Transformers app using old examples. Plan the model-loading and tokenizer migration together, retain a rollback lock, and compare behavior before accepting the upgrade.

Versions and licence, checked 2026-11-24

ItemVerified statusSource
Transformers 5.0.0 (checked 2026-10-20)Initial major release, 2026-01-26 (checked 2026-10-20)PyPI
As of November 2026, Transformers 5.24.0 (checked 2026-11-24)PyPI release, 2026-11-21; Apache 2.0; Python >=3.11.0 (checked 2026-11-24)PyPI metadata

Model licences are separate; no hosting price comparison is needed for this library migration.

What changed

  • The 2026-01-26 release (checked 2026-10-20) removed TensorFlow/JAX support. Loading defaults to dtype="auto", preserving checkpoint precision instead of forcing float32. Top-level load_in_4bit and load_in_8bit gave way to quantization_config. Official release notes.
  • That major transition, dated 2026-01-26 (checked 2026-10-20), removed AutoModelWithLMHead and AutoModelForVision2Seq. Tokenizers consolidate backends; encode_plus gives way to __call__, decode handles batches, and tokenized apply_chat_template returns BatchEncoding. New saves consolidate legacy token files. Official migration guide.

Device placement is separate from dtype. The model API, checked 2026-10-20, accepts a single device or module map; device_map="auto" explicitly enables Accelerate dispatch. The loading source, checked 2026-10-20, documents CPU checkpoint loading and honors device contexts. Do not infer a new automatic GPU default. Explicitly choose device_map="cpu" for a controlled baseline, then test accelerator placement.

What breaks

SymptomInvestigate first
ImportError: cannot import name 'AutoModelForVision2Seq' from 'transformers'Removed class, including imports inside wrappers; downstream report, checked 2026-10-20
Chat call expects a tensorInspect the mapping and pass named generation inputs
Different token IDs or decoded outputCompare tokenizer assets, special tokens and batch shapes
Changed output or memory footprintRecord actual dtype and device placement

The last three are diagnostic expectations, not reproduced error messages.

When to pick which path

ConstraintRecommendation
TensorFlow/JAX applicationRetain the working lock while planning a backend rewrite
Native PyTorch modelMigrate a small inference path in an isolated environment
Wrapper imports removed internalsUpgrade wrapper and library as a supported pair
Custom model/tokenizer codeAudit imports and tokenization assumptions before updating

How to migrate

1. Save the old lock and representative input/output fixtures. Record checkpoint revision, tokenizer assets, dtype and placement. The installation guide, checked 2026-10-20, recommends isolation. This editorial pin uses the verified PyPI release 5.20.2 (checked 2026-10-20), rather than copying an unpinned install:

python -m venv .transformers-migration
. .transformers-migration/bin/activate
python -m pip install 'transformers[torch]==5.20.2'
python -m pip check

2. Apply the migration guide's exact replacements, checked 2026-10-20. Replace AutoModelForVision2Seq with AutoModelForImageTextToText. For AutoModelWithLMHead, select AutoModelForCausalLM, AutoModelForMaskedLM or AutoModelForSeq2SeqLM by task. Use tokenizer(...), inspect decode return shapes, and preserve the whole saved tokenizer directory. 3. Make loading explicit. The loading guide, checked 2026-10-20, explains dtype inference from config or floating-point weights, hf_device_map, and max_memory/offload_folder. Use dtype=torch.float32 if preserving old precision is your baseline; compare intended checkpoint precision separately. Follow the quantization guide, checked 2026-10-20, with quantization_config=BitsAndBytesConfig(load_in_4bit=True). 4. Adapt chat generation using the official chat guide and exact ID on the model page, checked 2026-10-20. Here model and tokenizer must already use that same checkpoint; select loading policy separately:

messages = [{"role": "user", "content": "Hello"}]
inputs = tokenizer.apply_chat_template(
    messages, tokenize=True, add_generation_prompt=True, return_tensors="pt"
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=32)
print(tokenizer.decode(outputs[0]))

What to test

Compare single/batched token IDs, padding masks, special tokens, role boundaries and save/reload behavior. Run a forward pass and short generation, then representative context lengths. Inspect dtype, device map, peak loading memory and quantized layer types. Run a tiny training/resume cycle if relevant. These are proposed acceptance checks, not measured results.

Community evidence

  • NVIDIA issue #12321, checked 2026-10-20: ernestyalumni reports the removed vision Auto import; collaborator karljang tracks a coordinated upgrade. This demonstrates wrapper risk, not universal breakage.
  • Transformers issue #43032, checked 2026-10-20: jwm1969 reports quantized-loading OOM; other participants confirm similar failures and dispute the CPU-then-GPU workaround. Historical regression evidence does not prove the current pin fails.

Pitfalls

A renamed class does not establish new architecture support. A successful import does not validate generation. Blanket float32 conversion can exhaust GPU memory. The chat guide warns against duplicating special tokens when separately tokenizing rendered chat; use add_special_tokens=False in that path.

A prompt to give your agent

Your training data predates this migration. Read the linked official migration guide and release notes now; do not guess removed APIs, tokenizer return types or defaults. Inventory installed packages and wrapper constraints, cite exact replacements, and migrate one path in an isolated environment. Record checkpoint revision, dtype, device map and tokenizer files. Run the acceptance checks, retain a rollback lock and report unverified behavior.

Limits

No model was installed, loaded, trained or benchmarked. The evolving migration guide includes early candidate caveats; these are not treated as current failures or assigned patch dates. No changed automatic GPU default was established. Two GitHub discussions provide evidence; engagement counts were unavailable. Checked 2026-10-20.

Started from a post by @huggingface, packaged by the editor. Original post

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# Transformers v4 to v5: how do I migrate loading and tokenizers?
Summary: As of November 2026, migrate Transformers loading and tokenizers together: replace removed Auto classes, handle chat inputs as mappings, and explicitly test dtype and placement against your old lock. PyPI lists 5.24.0 (checked 2026-11-24).
Copy for agent
get the whatworks thread transformers-v4-to-v5-migrate-loading-and-tokenizers and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread transformers-v4-to-v5-migrate-loading-and-tokenizers
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks