{"record":{"id":"5afaeec9a3c73594","repo":"opendatalab/MinerU","slug":"config-name-or-path-is-required-by-unimernetmodel","errorCode":null,"errorMessage":"config._name_or_path is required by UnimernetModel.","messagePattern":"config\\._name_or_path is required by UnimernetModel\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"mineru/model/mfr/unimernet/unimernet_hf/modeling_unimernet.py","lineNumber":76,"sourceCode":"                    del toks[b][i]\n        return toks\n\nclass UnimernetModel(VisionEncoderDecoderModel):\n    def __init__(\n        self,\n        config: Optional[PretrainedConfig] = None,\n        encoder: Optional[PreTrainedModel] = None,\n        decoder: Optional[PreTrainedModel] = None,\n    ):\n        # VisionEncoderDecoderModel's checking log has bug, disable for temp.\n        base_model_logger.disabled = True\n        try:\n            super().__init__(config, encoder, decoder)\n        finally:\n            base_model_logger.disabled = False\n\n        if not config or not hasattr(config, \"_name_or_path\"):\n            raise RuntimeError(\"config._name_or_path is required by UnimernetModel.\")\n\n        model_path = config._name_or_path\n        self.transform = UnimerSwinImageProcessor()\n        self.tokenizer = TokenizerWrapper(AutoTokenizer.from_pretrained(model_path))\n        self._post_check()\n    \n    def _post_check(self):\n        tokenizer = self.tokenizer\n\n        if tokenizer.tokenizer.model_max_length != self.config.decoder.max_position_embeddings:\n            warnings.warn(\n                f\"decoder.max_position_embeddings={self.config.decoder.max_position_embeddings},\" +\n                f\" but tokenizer.model_max_length={tokenizer.tokenizer.model_max_length}, will set\" +\n                f\" tokenizer.model_max_length to {self.config.decoder.max_position_embeddings}.\")\n            tokenizer.tokenizer.model_max_length = self.config.decoder.max_position_embeddings\n\n        assert self.config.decoder.vocab_size == len(tokenizer)\n        assert self.config.decoder_start_token_id == tokenizer.bos_token_id","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/opendatalab/MinerU/blob/4fe4bde114a23ee5dd637eae99b767f4669bf58c/mineru/model/mfr/unimernet/unimernet_hf/modeling_unimernet.py#L58-L94","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Load via UnimernetModel.from_pretrained(<local model dir>) where the dir contains tokenizer files and config.json with _name_or_path set.","Set config._name_or_path = '/abs/path/to/unimernet' before constructing the model.","Ensure the referenced directory actually contains tokenizer.json / tokenizer_config.json.","Use an absolute path; relative _name_or_path breaks when the process cwd changes."],"exampleFix":"# before\nconfig = PretrainedConfig.from_dict(cfg_dict)  # no _name_or_path\nmodel = UnimernetModel(config=config, encoder=..., decoder=...)\n\n# after\nconfig._name_or_path = str(model_dir)\nmodel = UnimernetModel(config=config, encoder=..., decoder=...)","handlingStrategy":"validation","validationCode":"cfg_dict = json.load(open(model_dir / 'config.json'))\nif not cfg_dict.get('_name_or_path'):\n    cfg_dict['_name_or_path'] = str(model_dir)\n    json.dump(cfg_dict, open(model_dir / 'config.json', 'w'))","typeGuard":"def config_has_model_path(config) -> bool:\n    return bool(getattr(config, '_name_or_path', None))","tryCatchPattern":"try:\n    model = UnimernetModel(config=config, encoder=enc, decoder=dec)\nexcept RuntimeError as e:\n    if '_name_or_path' in str(e):\n        config._name_or_path = str(model_dir)\n        model = UnimernetModel(config=config, encoder=enc, decoder=dec)\n    else:\n        raise","preventionTips":["Always load via from_pretrained(model_dir) with tokenizer files present in the dir.","Smoke-test model loading at deploy time, not on first user request.","Use absolute paths for _name_or_path."],"tags":["model-loading","configuration","formula-recognition"],"backgroundTag":null,"analyzedSha":"4fe4bde114a23ee5dd637eae99b767f4669bf58c","analyzedAt":"2026-08-14T21:29:18.456Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}