hankcs/HanLP · warning · FutureWarning

The class `PretrainedBartModel` has been depreciated, please

Error message

The class `PretrainedBartModel` has been depreciated, please use `BartPretrainedModel` instead.

What it means

FutureWarning emitted by __init_subclass__ whenever anything subclasses the deprecated alias PretrainedBartModel (from the vendored AMR-BART modeling file). It mirrors HuggingFace's deprecation; the real class is BartPretrainedModel.

Source

Thrown at hanlp/components/amr/amrbart/model_interface/modeling_bart.py:530

    def _set_gradient_checkpointing(self, module, value=False):
        if isinstance(module, (BartDecoder, BartEncoder)):
            module.gradient_checkpointing = value

    @property
    def dummy_inputs(self):
        pad_token = self.config.pad_token_id
        input_ids = torch.tensor([[0, 6, 10, 4, 2], [0, 8, 12, 2, pad_token]], device=self.device)
        dummy_inputs = {
            "attention_mask": input_ids.ne(pad_token),
            "input_ids": input_ids,
        }
        return dummy_inputs


class PretrainedBartModel(BartPretrainedModel):
    def __init_subclass__(self):
        warnings.warn(
            "The class `PretrainedBartModel` has been depreciated, please use `BartPretrainedModel` instead.",
            FutureWarning,
        )


BART_START_DOCSTRING = r"""
    This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
    library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
    etc.)

    This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
    Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
    and behavior.

    Parameters:
        config ([`BartConfig`]):
            Model configuration class with all the parameters of the model. Initializing with a config file does not
            load the weights associated with the model, only the configuration. Check out the

View on GitHub (pinned to ddb1299bdd)

Solutions

  1. Replace the base class with BartPretrainedModel
  2. If the subclasser is third-party code you can't change, filter FutureWarning for this message
  3. Pin/upgrade to a HanLP version consistent with your vendored modeling file

Example fix

# before
class MyBart(PretrainedBartModel): ...
# after
class MyBart(BartPretrainedModel): ...
Defensive patterns

Strategy: try-catch

Try / catch

import warnings
with warnings.catch_warnings():
    warnings.filterwarnings('ignore', category=FutureWarning, message='.*PretrainedBartModel.*')
    import my_old_bart_module  # subclasses the alias

Prevention

When it happens

Trigger: Defining any class PretrainedBartModel as base, or importing old user code / third-party code that subclasses PretrainedBartModel during class definition.

Common situations: Porting older HF-style BART fine-tuning code into HanLP's AMR component; version upgrades from when the alias was the public name.

Related errors


AI-assisted analysis of hankcs/HanLP@ddb1299bdd (2026-08-27). Data as JSON: /api/errors/1e9750631104a1f3. Report an issue: GitHub.