opendatalab/MinerU · critical · RuntimeError

config._name_or_path is required by UnimernetModel.

Error message

config._name_or_path is required by UnimernetModel.

What it means

UnimernetModel's __init__ needs config._name_or_path because it loads the tokenizer via AutoTokenizer.from_pretrained(model_path) from the same directory as the model weights. A PretrainedConfig without _name_or_path (constructed in memory, or from a config dict without the field) cannot locate those tokenizer files, so init fails fast with this RuntimeError.

Source

Thrown at mineru/model/mfr/unimernet/unimernet_hf/modeling_unimernet.py:76

                    del toks[b][i]
        return toks

class UnimernetModel(VisionEncoderDecoderModel):
    def __init__(
        self,
        config: Optional[PretrainedConfig] = None,
        encoder: Optional[PreTrainedModel] = None,
        decoder: Optional[PreTrainedModel] = None,
    ):
        # VisionEncoderDecoderModel's checking log has bug, disable for temp.
        base_model_logger.disabled = True
        try:
            super().__init__(config, encoder, decoder)
        finally:
            base_model_logger.disabled = False

        if not config or not hasattr(config, "_name_or_path"):
            raise RuntimeError("config._name_or_path is required by UnimernetModel.")

        model_path = config._name_or_path
        self.transform = UnimerSwinImageProcessor()
        self.tokenizer = TokenizerWrapper(AutoTokenizer.from_pretrained(model_path))
        self._post_check()
    
    def _post_check(self):
        tokenizer = self.tokenizer

        if tokenizer.tokenizer.model_max_length != self.config.decoder.max_position_embeddings:
            warnings.warn(
                f"decoder.max_position_embeddings={self.config.decoder.max_position_embeddings}," +
                f" but tokenizer.model_max_length={tokenizer.tokenizer.model_max_length}, will set" +
                f" tokenizer.model_max_length to {self.config.decoder.max_position_embeddings}.")
            tokenizer.tokenizer.model_max_length = self.config.decoder.max_position_embeddings

        assert self.config.decoder.vocab_size == len(tokenizer)
        assert self.config.decoder_start_token_id == tokenizer.bos_token_id

View on GitHub (pinned to 4fe4bde114)

Solutions

  1. Load via UnimernetModel.from_pretrained(<local model dir>) where the dir contains tokenizer files and config.json with _name_or_path set.
  2. Set config._name_or_path = '/abs/path/to/unimernet' before constructing the model.
  3. Ensure the referenced directory actually contains tokenizer.json / tokenizer_config.json.
  4. Use an absolute path; relative _name_or_path breaks when the process cwd changes.

Example fix

# before
config = PretrainedConfig.from_dict(cfg_dict)  # no _name_or_path
model = UnimernetModel(config=config, encoder=..., decoder=...)

# after
config._name_or_path = str(model_dir)
model = UnimernetModel(config=config, encoder=..., decoder=...)
Defensive patterns

Strategy: validation

Validate before calling

cfg_dict = json.load(open(model_dir / 'config.json'))
if not cfg_dict.get('_name_or_path'):
    cfg_dict['_name_or_path'] = str(model_dir)
    json.dump(cfg_dict, open(model_dir / 'config.json', 'w'))

Type guard

def config_has_model_path(config) -> bool:
    return bool(getattr(config, '_name_or_path', None))

Try / catch

try:
    model = UnimernetModel(config=config, encoder=enc, decoder=dec)
except RuntimeError as e:
    if '_name_or_path' in str(e):
        config._name_or_path = str(model_dir)
        model = UnimernetModel(config=config, encoder=enc, decoder=dec)
    else:
        raise

Prevention

When it happens

Trigger: Instantiating UnimernetModel(config=PretrainedConfig.from_dict({...})) where the dict lacks _name_or_path; loading with from_pretrained on a directory that has config.json without a _name_or_path field; or deep-copying/reconstructing the config programmatically.

Common situations: Loading a locally converted Unimernet checkpoint whose config.json was hand-written, pointing _name_or_path at a relative or moved directory, or initializing the model from a config object built for unit tests.

Related errors


AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14). Data as JSON: /api/errors/5afaeec9a3c73594. Report an issue: GitHub.