huggingface/pytorch-image-models · warning

DropBlock2d() got unexpected keyword argument '{k}'

Error message

DropBlock2d() got unexpected keyword argument '{k}'

What it means

DropBlock2d in timm/layers/drop.py consumes unknown **kwargs with a warning for backwards compatibility: removed args ('batchwise', 'fast') are silently ignored, but any other unexpected keyword (e.g. 'drop_prob' misspelled, 'gamma', 'block_size' typo) triggers this warning and the arg is dropped.

Source

Thrown at timm/layers/drop.py:141

            couple_channels: bool = True,
            scale_by_keep: bool = True,
            **kwargs,
    ):
        super().__init__()
        self.drop_prob = drop_prob
        self.gamma_scale = gamma_scale
        self.block_size = block_size
        self.with_noise = with_noise
        self.inplace = inplace
        self.couple_channels = couple_channels
        self.scale_by_keep = scale_by_keep

        # Backwards compatibility: silently consume args removed in v1.0.23, warn on unknown
        deprecated_args = {'batchwise', 'fast'}
        for k in kwargs:
            if k not in deprecated_args:
                import warnings
                warnings.warn(f"DropBlock2d() got unexpected keyword argument '{k}'")

    def forward(self, x):
        if not self.training or not self.drop_prob:
            return x
        return drop_block_2d(
            x,
            drop_prob=self.drop_prob,
            block_size=self.block_size,
            gamma_scale=self.gamma_scale,
            with_noise=self.with_noise,
            inplace=self.inplace,
            couple_channels=self.couple_channels,
            scale_by_keep=self.scale_by_keep,
        )


def drop_path(x, drop_prob: float = 0., training: bool = False, scale_by_keep: bool = True):
    """Drop paths (Stochastic Depth) per sample (when applied in main path of residual blocks).

View on GitHub (pinned to 9a5261e31b)

Solutions

  1. Remove or fix misspelled kwargs so only drop_prob and block_size are passed
  2. Delete legacy 'batchwise'/'fast' args from configs (they do nothing now)
  3. If a config dict is splatted, filter keys to the known signature

Example fix

# before
drop = DropBlock2d(drop_prob=0.1, block_size=7, batchwise=True, fast=True, prob=0.2)
# after
drop = DropBlock2d(drop_prob=0.1, block_size=7)
Defensive patterns

Strategy: validation

Validate before calling

import inspect\nfrom timm.layers.drop import DropBlock2d\nvalid = set(inspect.signature(DropBlock2d.__init__).parameters) | {'batchwise', 'fast'}\nkwargs = {k: v for k, v in cfg.items() if k in valid}

Prevention

When it happens

Trigger: Passing DropBlock2d(drop_prob=0.1, block_size=7, batchwise=True) (ignored silently); or a misspelled/foreign kwarg like DropBlock2d(prob=0.1, size=7) which warns and is discarded.

Common situations: Old training scripts from timm <1.0.23; copy-pasting DropPath-style args; config systems that pass all hparams through **kwargs, leaking unrelated keys into DropBlock2d.

Related errors


AI-assisted analysis of huggingface/pytorch-image-models@9a5261e31b (2026-08-27). Data as JSON: /api/errors/0725152939303d56. Report an issue: GitHub.