{"record":{"id":"4e810c939f28316f","repo":"hiyouga/LlamaFactory","slug":"recompute-method-must-be-uniform-or-block","errorCode":null,"errorMessage":"`recompute_method` must be 'uniform' or 'block'.","messagePattern":"`recompute_method` must be 'uniform' or 'block'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/llamafactory/hparams/megatron_bridge_args.py","lineNumber":168,"sourceCode":"    )\n\n    def __post_init__(self) -> None:\n        if self.tensor_model_parallel_size < 1:\n            raise ValueError(\"`tensor_model_parallel_size` must be >= 1.\")\n        if self.pipeline_model_parallel_size < 1:\n            raise ValueError(\"`pipeline_model_parallel_size` must be >= 1.\")\n        if self.expert_model_parallel_size < 1:\n            raise ValueError(\"`expert_model_parallel_size` must be >= 1.\")\n        if self.context_parallel_size < 1:\n            raise ValueError(\"`context_parallel_size` must be >= 1.\")\n        if self.virtual_pipeline_model_parallel_size is not None and self.virtual_pipeline_model_parallel_size < 1:\n            raise ValueError(\"`virtual_pipeline_model_parallel_size` must be >= 1 when set.\")\n        if self.sequence_parallel and self.tensor_model_parallel_size <= 1:\n            raise ValueError(\"`sequence_parallel` requires `tensor_model_parallel_size` > 1.\")\n        if self.recompute_granularity is not None and self.recompute_granularity not in (\"full\", \"selective\"):\n            raise ValueError(\"`recompute_granularity` must be 'full' or 'selective'.\")\n        if self.recompute_method is not None and self.recompute_method not in (\"uniform\", \"block\"):\n            raise ValueError(\"`recompute_method` must be 'uniform' or 'block'.\")\n        if self.recompute_num_layers is not None and self.recompute_num_layers < 1:\n            raise ValueError(\"`recompute_num_layers` must be >= 1 when set.\")\n        if self.moe_token_dispatcher_type is not None and self.moe_token_dispatcher_type not in (\n            \"allgather\",\n            \"alltoall\",\n            \"flex\",\n        ):\n            raise ValueError(\"`moe_token_dispatcher_type` must be 'allgather', 'alltoall', or 'flex'.\")\n\n        if isinstance(self.extra_config, str):\n            config_str = self.extra_config.strip()\n            if config_str.startswith(\"{\"):\n                self.extra_config = _convert_str_dict(json.loads(config_str))\n            else:\n                self.extra_config = config_str\n\n    def load_extra_config(self) -> dict:\n        if self.extra_config is None:","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/hiyouga/LlamaFactory/blob/f28afaf6355af515454dfb16c97d728307c93897/src/llamafactory/hparams/megatron_bridge_args.py#L150-L186","documentation":"Raised in MegatronBridgeArguments.__post_init__ (megatron_bridge_args.py:168) when recompute_method is set to a string other than 'uniform' or 'block'. The method controls how recompute_num_layers layers are chosen for recomputation: 'uniform' spreads them evenly across transformer layers, 'block' chunks them contiguously per pipeline stage. It is validated as an exact lowercase string and only matters when recompute_granularity is 'full'.","triggerScenarios":"Setting recompute_method: uniform/block with wrong casing or a typo ('blocks', 'Uniform'); providing a Megatron-core enum name like 'RecomputeMethod.UNIFORM' as a string; setting the method without setting recompute_granularity/full first.","commonSituations":"Transcribing values from Megatron-LM launch scripts; LLM-assisted configs inventing plausible values; refactors that renamed the field's accepted vocabulary.","solutions":["Use exactly 'uniform' or 'block' (lowercase)","Pair it with recompute_granularity: full and a positive recompute_num_layers","Remove recompute_method if you do not need deterministic block/uniform placement"],"exampleFix":"# before\nrecompute_method: blocks\n\n# after\nrecompute_granularity: full\nrecompute_method: uniform\nrecompute_num_layers: 1","handlingStrategy":"validation","validationCode":"if cfg.get('recompute_method') not in (None, 'uniform', 'block'):\n    raise SystemExit(f\"bad recompute_method: {cfg['recompute_method']!r}\")","typeGuard":"def is_valid_recompute_method(v: str | None) -> bool:\n    return v in (None, 'uniform', 'block')","tryCatchPattern":null,"preventionTips":["Set recompute_method only together with recompute_granularity: full","Prefer deleting the key over guessing values"],"tags":["megatron","activation-checkpointing","config-validation"],"backgroundTag":null,"analyzedSha":"f28afaf6355af515454dfb16c97d728307c93897","analyzedAt":"2026-08-14T21:57:28.298Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}