Skip to content

fix(export): resolve timm image_size from pretrained_cfg#806

Open
vortex-captain wants to merge 6 commits into
mainfrom
reny/timm_pre_cfg
Open

fix(export): resolve timm image_size from pretrained_cfg#806
vortex-captain wants to merge 6 commits into
mainfrom
reny/timm_pre_cfg

Conversation

@vortex-captain
Copy link
Copy Markdown
Contributor

Summary

  • Fix winml config emitting [1, 3, 64, 64] instead of [1, 3, 224, 224] for timm image-classification models (e.g. timm/repghostnet_200.in1k).
  • Root cause: TimmWrapperConfig stores shape info in pretrained_cfg["input_size"] (a plain dict). Optimum's NormalizedConfig only walks PretrainedConfig children, so the value is invisible to DummyVisionInputGenerator, which then defaults to 64x64. timm models also have no preprocessor_config.json on the hub, so winml's existing fallback misses too.
  • Fix: when preprocessor_config.json is unavailable, synthesize a preprocessor-style dict from hf_config.pretrained_cfg.input_size. The existing size-parsing block (size int / dict-with-height-width / shortest_edge) is unchanged — the timm concern is isolated at the data-fetch boundary in _get_preprocessor_dict / _synthesize_preprocessor_dict.
  • Registry: added timm/mobilenetv3_small_100.lamb_in1k and timm/repghostnet_200.in1k to models_all.json; both PASS perf on CPU. Perf output confirms pixel_values [1, 3, 224, 224] float32.

🤖 Generated with Claude Code

Optimum's DummyVisionInputGenerator falls back to 64x64 when normalized_config
lacks image_size/input_size. For timm models loaded via TimmWrapperConfig,
input_size lives nested in pretrained_cfg as a plain dict, which Optimum's
NormalizedConfig does not traverse, and preprocessor_config.json is absent
on the hub. So winml config emitted [1, 3, 64, 64] instead of [1, 3, 224, 224].

Synthesize a preprocessor_config-style dict from pretrained_cfg.input_size
when the hub fetch misses, keeping the existing size-parsing block intact.
Added timm/mobilenetv3_small_100.lamb_in1k and timm/repghostnet_200.in1k to
the e2e registry; both PASS perf on CPU with the correct [1, 3, 224, 224] shape.
@vortex-captain vortex-captain requested a review from a team as a code owner June 3, 2026 07:49
@timenick
Copy link
Copy Markdown
Collaborator

timenick commented Jun 4, 2026

CI failure here is unrelated to this PR — it's network-dependent unit tests

The failing job (run 26930137132) is erroring on tests/unit/export/test_io.py, not on the timm change in this PR. All 9 errors are the same OSError:

OSError: We couldn't connect to 'https://huggingface.co' to load the files,
and couldn't find them in the cached files.

Root cause: two module-scoped fixtures pull configs from the HF Hub at collection time:

These fixtures and the T5/Qwen test classes were introduced in #334 (feat: multi-model support with KV cache (T5, Qwen, Mu2), commit 38775de8).

A unit test shouldn't require network access — it makes the suite fail on offline runners, behind firewalls, or whenever the Hub is unavailable, which is exactly what hit this PR.

Suggested fix: build these configs synthetically, the way the Marian/BART tests in the same file already do (e.g. marian_config constructs MarianConfig(...) directly with small dims, no network). T5/Qwen can do the same. If a real from_pretrained download is genuinely needed, those cases belong under tests/integration/, not tests/unit/.

Generated with Claude Code

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.

2 participants