{"record":{"id":"a889dd71df6a396b","repo":"tensorflow/models","slug":"maskedrouter-is-an-abstract-class-that-should-be-s","errorCode":null,"errorMessage":"MaskedRouter is an abstract class that should be subclassed.","messagePattern":"MaskedRouter is an abstract class that should be subclassed\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"official/nlp/modeling/layers/moe.py","lineNumber":233,"sourceCode":"  Routing using masked matmuls is generally faster than scatter-based routing on\n  TPUs.\n\n  Uses Keras add_loss() and add_metric() APIs.\n  \"\"\"\n\n  def _compute_routing_instructions(self, router_probs: tf.Tensor,\n                                    expert_capacity: int) -> RouterMask:\n    \"\"\"Computes masks for the top-k experts per token.\n\n    Args:\n      router_probs: <float32>[num_groups, tokens_per_group, num_experts]\n        probabilities used to determine the routing of tokens to the experts.\n      expert_capacity: Each group will send this many tokens to each expert.\n\n    Returns:\n      Router mask arrays.\n    \"\"\"\n    raise NotImplementedError(\n        \"MaskedRouter is an abstract class that should be subclassed.\")\n\n\nclass ExpertsChooseMaskedRouter(MaskedRouter):\n  \"\"\"Masked matmul router using experts choose tokens assignment.\n\n  This router uses the same mechanism as in Mixture-of-Experts with Expert\n  Choice (https://arxiv.org/abs/2202.09368): each expert selects its top\n  expert_capacity tokens. An individual token may be processed by multiple\n  experts or none at all.\n\n  Note: \"experts choose routing\" should not be used in decoder blocks because it\n  breaks the autoregressive behavior, leading to a mismatch between training\n  (teacher forcing) and inference (autoregressive decoding).\n\n  Uses Keras add_loss() and add_metric() APIs.\n  \"\"\"\n","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/nlp/modeling/layers/moe.py#L215-L251","documentation":"Error \"MaskedRouter is an abstract class that should be subclassed.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/nlp/modeling/layers/moe.py:233 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}