transformers - ✅(Solved) Fix Less verbose `tqdm` weight loading (`Loading weights: 38% ... Materializing param=....]` log) [2 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
huggingface/transformers#44303Fetched 2026-04-08 00:29:13
View on GitHub
Comments
0
Participants
1
Timeline
7
Reactions
0
Participants
Timeline (top)
cross-referenced ×2referenced ×2closed ×1labeled ×1

Fix Action

Fixed

PR fix notes

PR #44316: Reduce tqdm verbosity during weight loading

Description (problem / solution / changelog)

Fixes #44303

The weight loading progress bar called pbar.refresh() on every single parameter, bypassing tqdm's built-in rate-limiting. When output is redirected to a log file (e.g. in CI), this produced one line per parameter -- hundreds or thousands of lines like:

Loading weights:  38%|███▊      | 74/197 [..., Materializing param=model.decoder.layers.4.final_layer_norm.bias]
Loading weights:  38%|███▊      | 74/197 [..., Materializing param=model.decoder.layers.4.final_layer_norm.bias]
Loading weights:  38%|███▊      | 75/197 [..., Materializing param=model.decoder.layers.4.final_layer_norm.weight]

Fix: remove the explicit refresh() and pass refresh=False to set_postfix, letting tqdm use its default mininterval=0.1s rate-limiting. The progress bar still updates in interactive terminals but no longer floods log files.

Changed files

  • src/transformers/core_model_loading.py (modified, +2/-3)

PR #44414: Reduce tqdm verbosity during model loading

Description (problem / solution / changelog)

What does this PR do?

Fixes https://github.com/huggingface/transformers/issues/44303 - see also comments here https://github.com/huggingface/transformers/pull/44316#issuecomment-3984362089. Supersedes https://github.com/huggingface/transformers/pull/44316

Changed files

  • src/transformers/core_model_loading.py (modified, +35/-39)

Code Example

Loading weights:  38%|███▊      | 74/197 [00:00<00:00, 11546.82it/s, Materializing param=model.decoder.layers.4.final_layer_norm.bias]
Loading weights:  38%|███▊      | 74/197 [00:00<00:00, 11490.82it/s, Materializing param=model.decoder.layers.4.final_layer_norm.bias]
Loading weights:  38%|███▊      | 75/197 [00:00<00:00, 11550.31it/s, Materializing param=model.decoder.layers.4.final_layer_norm.weight]
Loading weights:  38%|███▊      | 75/197 [00:00<00:00, 11495.44it/s, Materializing param=model.decoder.layers.4.final_layer_norm.weight]
Loading weights:  39%|███▊      | 76/197 [00:00<00:00, 11556.23it/s, Materializing param=model.decoder.layers.4.self_attn.k_proj.bias]  
Loading weights:  39%|███▊      | 76/197 [00:00<00:00, 11500.36it/s, Materializing param=model.decoder.layers.4.self_attn.k_proj.bias]
Loading weights:  39%|███▉      | 77/197 [00:00<00:00, 11549.60it/s, Materializing param=model.decoder.layers.4.self_attn.k_proj.weight]
Loading weights:  39%|███▉      | 77/197 [00:00<00:00, 11494.52it/s, Materializing param=model.decoder.layers.4.self_attn.k_proj.weight]
RAW_BUFFERClick to expand / collapse

Feature request

Hello,

Currently when redirecting any PretrainedModel.from_pretrained to log file, we get a huge:

Loading weights:  38%|███▊      | 74/197 [00:00<00:00, 11546.82it/s, Materializing param=model.decoder.layers.4.final_layer_norm.bias]
Loading weights:  38%|███▊      | 74/197 [00:00<00:00, 11490.82it/s, Materializing param=model.decoder.layers.4.final_layer_norm.bias]
Loading weights:  38%|███▊      | 75/197 [00:00<00:00, 11550.31it/s, Materializing param=model.decoder.layers.4.final_layer_norm.weight]
Loading weights:  38%|███▊      | 75/197 [00:00<00:00, 11495.44it/s, Materializing param=model.decoder.layers.4.final_layer_norm.weight]
Loading weights:  39%|███▊      | 76/197 [00:00<00:00, 11556.23it/s, Materializing param=model.decoder.layers.4.self_attn.k_proj.bias]  
Loading weights:  39%|███▊      | 76/197 [00:00<00:00, 11500.36it/s, Materializing param=model.decoder.layers.4.self_attn.k_proj.bias]
Loading weights:  39%|███▉      | 77/197 [00:00<00:00, 11549.60it/s, Materializing param=model.decoder.layers.4.self_attn.k_proj.weight]
Loading weights:  39%|███▉      | 77/197 [00:00<00:00, 11494.52it/s, Materializing param=model.decoder.layers.4.self_attn.k_proj.weight]

with many lines.

This comes from https://github.com/huggingface/transformers/blob/af5dfb6c5cb98091aa76c2c768bd4b7a38891b01/src/transformers/core_model_loading.py#L1203

This makes log files huge, especially in CI which loads many models.

Could we consider making this less verbose?

Thank you!

Motivation

Several tens of hundreds of thousands lines CI log files

Your contribution

maybe

extent analysis

Fix Plan

Reduce Verbosity of Model Loading Logs

To reduce the verbosity of model loading logs, we can modify the transformers library to log only the progress bar and the final loading message.

Step-by-Step Solution

  1. Update core_model_loading.py:
import logging
from tqdm import tqdm

# ...

def _load_weights_from_file(model, config, weights_name, weights_path, logger):
    # ...

    # Log progress bar
    pbar = tqdm(total=len(model.config.model_args.layer_norm_groups), desc="Loading weights")
    for i, layer in enumerate(model.config.model_args.layer_norm_groups):
        # ...
        pbar.update(1)
    pbar.close()

    # Log final loading message
    logger.info("Loading weights complete.")
  1. Update __init__.py:
import logging

# ...

def from_pretrained(*args, **kwargs):
    # ...
    logger = logging.getLogger(__name__)
    # ...
  1. Update logging configuration:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")

Verification

  1. Run a test with PretrainedModel.from_pretrained and verify that the log file is smaller.
  2. Check that the progress bar and final loading message are still logged.

Extra Tips

  • You can further customize the logging configuration to suit your needs.
  • If you want to keep the original logging behavior for debugging purposes, you can add a flag to toggle between the two logging modes.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

transformers - ✅(Solved) Fix Less verbose `tqdm` weight loading (`Loading weights: 38% ... Materializing param=....]` log) [2 pull requests, 1 participants]