Commit 8abe7fd
Fix three Codex-review findings on variant= probe
[P2] Pass cache_dir through the variant probe.
``_variant_available`` and ``_resolve_variant`` previously didn't accept
``cache_dir``, so a caller using ``from_pretrained(..., cache_dir=X)``
would have ``hf_hub_download`` probe into the *default* HF cache and
then ``snapshot_download(..., cache_dir=X)`` could not reuse the probe's
download. Result: cold starts paid for the variant weights twice and
the user's requested cache location was bypassed. Both helpers now
take ``cache_dir`` and forward it to ``try_to_load_from_cache`` and
``hf_hub_download``.
[P2] Sharded variant safetensors.
``_variant_allow_patterns`` already included
``model.{variant}.safetensors.index.json`` for forward compatibility,
but the actual shard files
(``model-XXXXX-of-YYYYY.{variant}.safetensors``) were excluded by the
allow-list, so a publisher who shipped a sharded fp16 / bf16 variant
would get only the index file pulled — the load would then fail or
silently fall back to fp32. Added the ``model-*-of-*.{variant}.safetensors``
glob.
[P2] dtype-vs-variant consistency in the outer dispatcher.
``GLiNER.from_pretrained`` (the outer class-level dispatcher) ran the
variant probe before checking dtype/variant consistency. When the
variant file was missing from the Hub, ``_resolve_variant`` downgraded
to ``None`` and the inner consistency check was then skipped — silently
accepting ``variant='bf16', dtype='fp16'`` and loading fp16 instead of
raising the documented mismatch error. Hoisted the consistency check
above the probe in the outer dispatcher to mirror the inner logic.
Test coverage:
- New ``test_includes_sharded_safetensors_pattern`` asserts the shard
glob is per-variant (no cross-variant slip-through, default shards
still excluded).
- Updated ``test_fp16_and_bf16_differ_only_in_variant_filename`` to
account for the new shard pattern entries in the symmetric
difference.
- New ``test_outer_dispatcher_mismatch_raises_before_probe`` exercises
the outer-dispatcher path with a non-existent ``model_id`` and a
mismatched ``variant``/``dtype`` pair, asserting the ``ValueError``
fires before any I/O. Guards against the silent-fp16 regression.
90 unit tests pass (was 88 + 2 new). Ruff lint and format clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 0d3cf78 commit 8abe7fd
2 files changed
Lines changed: 95 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
327 | 331 | | |
328 | 332 | | |
329 | 333 | | |
330 | 334 | | |
331 | 335 | | |
332 | 336 | | |
| 337 | + | |
333 | 338 | | |
| 339 | + | |
334 | 340 | | |
| 341 | + | |
335 | 342 | | |
336 | 343 | | |
337 | 344 | | |
| |||
340 | 347 | | |
341 | 348 | | |
342 | 349 | | |
| 350 | + | |
343 | 351 | | |
344 | 352 | | |
345 | 353 | | |
| |||
375 | 383 | | |
376 | 384 | | |
377 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
378 | 389 | | |
379 | | - | |
| 390 | + | |
380 | 391 | | |
381 | 392 | | |
382 | 393 | | |
| |||
388 | 399 | | |
389 | 400 | | |
390 | 401 | | |
| 402 | + | |
| 403 | + | |
391 | 404 | | |
392 | | - | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
393 | 412 | | |
394 | 413 | | |
395 | 414 | | |
| |||
404 | 423 | | |
405 | 424 | | |
406 | 425 | | |
| 426 | + | |
407 | 427 | | |
408 | 428 | | |
409 | 429 | | |
| |||
420 | 440 | | |
421 | 441 | | |
422 | 442 | | |
423 | | - | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
424 | 449 | | |
425 | 450 | | |
426 | 451 | | |
| |||
1046 | 1071 | | |
1047 | 1072 | | |
1048 | 1073 | | |
| 1074 | + | |
1049 | 1075 | | |
1050 | 1076 | | |
1051 | 1077 | | |
| |||
4530 | 4556 | | |
4531 | 4557 | | |
4532 | 4558 | | |
| 4559 | + | |
| 4560 | + | |
| 4561 | + | |
| 4562 | + | |
| 4563 | + | |
| 4564 | + | |
| 4565 | + | |
| 4566 | + | |
| 4567 | + | |
| 4568 | + | |
| 4569 | + | |
| 4570 | + | |
| 4571 | + | |
| 4572 | + | |
| 4573 | + | |
| 4574 | + | |
| 4575 | + | |
| 4576 | + | |
| 4577 | + | |
| 4578 | + | |
| 4579 | + | |
| 4580 | + | |
4533 | 4581 | | |
4534 | 4582 | | |
4535 | 4583 | | |
4536 | 4584 | | |
4537 | 4585 | | |
4538 | 4586 | | |
4539 | 4587 | | |
| 4588 | + | |
4540 | 4589 | | |
4541 | 4590 | | |
4542 | 4591 | | |
4543 | | - | |
4544 | | - | |
4545 | | - | |
4546 | | - | |
4547 | | - | |
4548 | | - | |
4549 | 4592 | | |
4550 | 4593 | | |
4551 | 4594 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
295 | 296 | | |
296 | 297 | | |
297 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
298 | 304 | | |
299 | 305 | | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
300 | 319 | | |
301 | 320 | | |
302 | 321 | | |
| |||
339 | 358 | | |
340 | 359 | | |
341 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
342 | 380 | | |
343 | 381 | | |
344 | 382 | | |
| |||
0 commit comments