{"record":{"id":"da2586d318e7ca4e","repo":"xai-org/x-algorithm","slug":"namespace-is-already-exist-in-shardingcontext-s","errorCode":null,"errorMessage":"{namespace} is already exist in ShardingContext {self.name},{self.sharding_rules}","messagePattern":"(.+?) is already exist in ShardingContext (.+?),(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"phoenix/xrex/models/sharding_context.py","lineNumber":63,"sourceCode":"            f\"{name or 'unnamed'}={size}\" for name, size in zip(self.names, self.shape)\n        )\n        return f\"NamedShape({shape_str})\"\n\n\nclass ShardingContext:\n    def __init__(\n        self,\n        name: str,\n        mesh: jax.sharding.Mesh,\n        sharding_rules: dict[str, ShardingRule] | None = None,\n    ):\n        self.name = name\n        self.mesh = mesh\n        self.sharding_rules = {} if sharding_rules is None else sharding_rules\n\n    def register_sharding_rule(self, namespace: str) -> Callable[[ShardingRule], None]:\n        if namespace in self.sharding_rules:\n            raise ValueError(\n                f\"{namespace} is already exist in ShardingContext {self.name},{self.sharding_rules}\"\n            )\n\n        def _register_sharding_rule(rule: ShardingRule) -> \"ShardingContext\":\n            self.sharding_rules[namespace] = rule\n\n        return _register_sharding_rule\n\n    def logical_axis_to_physical(\n        self, logical_axis_name: str, namespace: str = \"default\", fallback_default: bool = True\n    ):\n        try:\n            sharding_rule = self.sharding_rules.get(namespace)\n            assert sharding_rule is not None, f\"Unknown sharding namespace: {namespace}\"\n            physical_axes = sharding_rule(logical_axis_name)\n        except Exception as e:\n            if fallback_default:\n                rank_logger.debug(f\"Falling back to default namespace from {namespace}.\")","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/xai-org/x-algorithm/blob/24c60942c5c5fdad3a6addffb4c6e6d2f228f04f/phoenix/xrex/models/sharding_context.py#L45-L81","documentation":"ShardingContext.register_sharding_rule keys rules by namespace string and refuses to register the same namespace twice. Registering a duplicate namespace raises this ValueError, which surfaces when make_sharding_context_from_config builds the context from your sharding config.","triggerScenarios":"A sharding config dict (or merged configs) that contains the same namespace key twice, e.g. {'mlp': ..., 'mlp': ...} after YAML merging, or two config files both defining rules for 'attention'.","commonSituations":"YAML anchors/merge keys (<<: *base) duplicating a namespace; inheriting a base config and re-declaring a section instead of overriding it.","solutions":["Inspect the merged config and remove the duplicate namespace entry before passing it to make_sharding_context_from_config","If overriding is intended, ensure the merge replaces rather than concatenates namespace keys","Use a distinct namespace name for genuinely different rules"],"exampleFix":"# before\nsharding:\n  attention: {in_dim: [\"data\"]}\n# ...later merge adds another 'attention' block\n# after\nsharding:\n  attention: {in_dim: [\"data\"], proj: [\"model\"]}  # single merged block per namespace","handlingStrategy":"validation","validationCode":"namespaces = [k for k in cfg['sharding']]\nassert len(namespaces) == len(set(namespaces)), 'duplicate namespace in sharding config'","typeGuard":null,"tryCatchPattern":"try:\n    ctx = make_sharding_context_from_config(cfg)\nexcept ValueError as e:\n    if 'is already exist in ShardingContext' in str(e):\n        raise ConfigError(f'duplicate namespace: {e}') from e\n    raise","preventionTips":["Validate merged config keys for duplicates before building the context","Use strict YAML loading that warns on duplicate keys"],"tags":["sharding","config","duplicate-key","jax"],"backgroundTag":"duplicate-config-key","analyzedSha":"24c60942c5c5fdad3a6addffb4c6e6d2f228f04f","analyzedAt":"2026-08-28T11:40:14.686Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}