{"record":{"id":"c1a8ce058f30f8e3","repo":"hankcs/HanLP","slug":"unrecognized-devices-devices","errorCode":null,"errorMessage":"Unrecognized devices {devices}","messagePattern":"Unrecognized devices (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"hanlp/common/torch_component.py","lineNumber":563,"sourceCode":"                        except StopIteration:\n                            continue\n                        if on_device == device:\n                            continue\n                        if isinstance(device, int):\n                            if on_device.index == device:\n                                continue\n                        if re.match(regex, name):\n                            if not name:\n                                name = '*'\n                            flash(f'Moving module [yellow]{name}[/yellow] to [on_yellow][magenta][bold]{device}'\n                                  f'[/bold][/magenta][/on_yellow]: [red]{regex}[/red]\\n')\n                            module.to(device)\n            elif isinstance(devices, torch.device):\n                if verbose:\n                    flash(f'Moving model to {devices} [blink][yellow]...[/yellow][/blink]')\n                self.model = self.model.to(devices)\n            else:\n                raise ValueError(f'Unrecognized devices {devices}')\n            if verbose:\n                flash('')\n        else:\n            if logger:\n                logger.info('Using [red]CPU[/red]')\n\n    def parallelize(self, devices: List[Union[int, torch.device]]):\n        return nn.DataParallel(self.model, device_ids=devices)\n\n    @property\n    def devices(self):\n        \"\"\"The devices this component lives on.\n        \"\"\"\n        if self.model is None:\n            return None\n        # next(parser.model.parameters()).device\n        if hasattr(self.model, 'device_ids'):\n            return self.model.device_ids","sourceCodeStart":545,"sourceCodeEnd":581,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/torch_component.py#L545-L581","documentation":"fit_dataloader on Word2VecEmbedding always raises NotImplementedError; static pretrained embeddings have no parameters to optimize over dataloader batches, so single-batch training is unsupported.","triggerScenarios":"Calling fit_dataloader (or fit with an existing dataloader) on a Word2VecEmbedding instance.","commonSituations":"Custom training loops that iterate components and call fit_dataloader generically; attempts to adapt embeddings to new vocabulary via training.","solutions":["Use the embedding only for forward lookups; rebuild the embedding if the vocab changed (it re-loads/re-maps vectors on load_vocabs)","Train a task component instead","Subclass to implement custom behavior"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"assert hasattr(model, 'build_optimizer') and not isinstance(model, Word2VecEmbedding)","typeGuard":"def is_trainable(m): return not isinstance(m, Word2VecEmbedding)","tryCatchPattern":"try:\n    model.fit_dataloader(trn, criterion, optimizer, metric, logger)\nexcept NotImplementedError:\n    logger.warning('fit_dataloader unsupported; skipping component')","preventionTips":["Skip embedding modules in generic batch-training loops","Rebuild embeddings instead of training them when vocab changes"],"tags":["hanlp","dataloader","embedding","not-implemented"],"backgroundTag":"not-implemented-error","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}