Emit `progress_total` events from `PreTrainedModel.from_pretrained()` (#1615)
* Emit progress_total events from PreTrainedModel.from_pretrained()
Closes #1052. When a progress_callback is provided, gather file
metadata (sizes) upfront via HEAD/Range requests before downloads
begin. This lets consumers build a single aggregate progress bar
across all model files, matching the behavior already present in the
pipeline() API.
The implementation reuses the existing get_model_files() and
get_file_metadata() utilities and follows the same wrapping pattern
used in pipelines.js, emitting progress_total events that include
per-file and overall loaded/total byte counts.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
* fix: address review — config.json progress + pipeline() duplication
Fixes two issues raised in code review:
1. config.json is fetched by AutoConfig.from_pretrained() before the
progress tracker is initialized. Pre-mark it as fully loaded in
files_loading so total progress reaches 100%.
2. pipeline() already wraps the callback with progress_total events.
When from_pretrained() wrapped it again, users got duplicate events.
Fix: mark wrapped callbacks with _progress_total_wrapped flag.
from_pretrained() checks the flag and skips wrapping if already set.
pipeline()'s wrapper now also sets this flag.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
* switched to wrapper-class instead of _progress_total_wrapped property
* created /src/models/session_config.js to avoid circular dependencies
* Use callable objects instead
* fix jsdoc
* fix imports
* Add strict progress callback unit tests
* Deduplicate concurrent loads and fix progress w/ node loading from path
* formatting
* increase larger whisper models loading times
* make tests stricter
---------
Co-authored-by: JacobiusMakes <jgalperin98@gmail.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: Nico Martin <mail@nico.dev>