Public report of hiyouga/LlamaFactory, published 14 November 2026. It has the same score, grades and number of
findings as the full report. The details of security findings (where they are in the code, which known
vulnerabilities and which passwords or keys were found) are left out, so nobody can use them against the project.
Public
Executive reportMeasured under the Code Assurance Index, an open standard for code quality, using its published scoring rules (rubric version 2026.11.4). Assert signed this survey and filed it in the standard's public register, where anyone can look it up by its survey ID. Check this survey →
Signed and filed in the standard's public register, 14 November 2026, 00:33 UTC · Survey ID cd_d08a67720a064bea961fc79105acf54a
hiyouga/LlamaFactory
Measured 14 November 2026, 00:32 UTC, at code version 5f1f6ad
CAI scoreAdequate
CriticalWeakAdequateStrongExemplary
No change since the last survey
The score is built from these lenses. Each lens grades one area of the code, such as how easy it is to change or how well it is protected. The weakest lens counts most, so one weak area pulls the score down instead of being averaged away.
A medium codebase: 45,085 lines of product code in 2 projects, tests not counted · Estimated rebuild effort: about 0.3 person-years · Weakest lens: Production Readiness, 41
Findings by how serious they are
56 critical459 serious64 minor
14 dimensions are left out of the score. For each one, we either couldn't measure it in this code, or found no evidence of the safeguard we look for, such as a tested backup restore. They count neither for nor against the score, and Limitations lists each one with its reason.
This survey was produced by
Canine Code Analyzer
Producer
Canine Development
Analyzer
Canine Code Analyzer engine 1.0.0
Measured
14 November 2026, 00:32 UTC
A measurement, not a certificate. The Code Assurance Index records a number
together with the evidence it was worked out from, so anyone can recalculate it, but it doesn't certify or guarantee
the code. The standard was written by Canine Development, which also builds the Canine Code Analyzer. It is open to any tool that
implements it, and today the Canine Code Analyzer is the only one that does.
The score is deterministic, which means the same code always gets the same score. We work it out with tools that follow published rules, and an AI model never decides it, so anyone who applies the same rules to the same code gets the same number. How it is done is explained under Methodology ▸
51of 51 dimensions measured by tools.
566of 579 findings point to an exact file and line, so you can open each one in the code. The other 13 concern the repository as a whole, such as missing documentation.
51dimensions across 6 lenses, read from 45,085 lines of product code in 2 projects.
hiyouga/LlamaFactory falls short of our standard for a preview release, in part because we found no automated security scanning of the code, its secrets or its dependencies. It scores 52 out of 100 and is rated Adequate, and 55 of its 56 critical findings are security problems in the build pipeline and in its servers and containers.
Production Readiness, at 41, is the weakest lens and counts most in the score. The best first step is adding automated security scanning, worth about 7 points. Protecting outgoing calls with timeouts comes next, worth about 4 points. Raising Production Readiness to 62 would lift the score to about 60.
Twenty-seven pipeline tools are referenced by a changeable name, so the build pipeline can be tampered with. Twenty settings leave the servers or containers unsafe, and seven secrets can leak from the build pipeline. Pinning each tool to an exact version, correcting the unsafe settings and limiting each secret to its own step would close these risks. The pipeline step that runs a download without checking it needs each download checked against a known checksum first. The part of the code nobody has worked on for a long time needs someone to learn and document it before anyone changes it.
The product code is 45,085 lines, about €51,000 to rebuild.
A lens is capped at Adequate while one of its dimensions scores below 4 out of 10, however well the rest of the lens does. That way a serious problem in one place always shows in the lens's rating.
How the score is built: what each lens counts forThe lenses don't count equally. The weakest lens counts most, the next weakest a little less, and so on, so a weak area pulls the score down instead of being averaged away. In the bar below, each part's width shows how much that lens counts and its colour shows its rating. Improving the widest part moves the score most, and as that lens improves, it counts for less, because another lens becomes the weakest.
Code Duplication · Near-duplicate member family (3 members, 43 shared lines) src/llamafactory/model/model_utils/longlora.py
Code Duplication · Edited copy of a member (77 corresponding lines) src/llamafactory/train/trainer_utils.py
Code Duplication · Edited copy of a member (72 corresponding lines) src/llamafactory/data/mm_plugin.py
Code Duplication · Edited copy of a member (43 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py
Code Duplication · Edited copy of a member (68 corresponding lines) src/llamafactory/train/dpo/trainer.py
Code Duplication · Edited copy of a member (60 corresponding lines) src/llamafactory/train/dpo/workflow.py
Code Duplication · Edited copy of a member (35 corresponding lines) src/llamafactory/data/mm_plugin.py
Code Duplication · Edited copy of a member (38 corresponding lines) src/llamafactory/data/mm_plugin.py
Code Duplication · Edited copy of a member (44 corresponding lines) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py
Code Duplication · Edited copy of a member (58 corresponding lines) src/llamafactory/v1/plugins/data_plugins/converter.py
Code Duplication · Edited copy of a member (33 corresponding lines) src/llamafactory/train/megatron_bridge/workflow.py
Code Duplication · Edited copy of a member (20 corresponding lines) src/llamafactory/data/template.py
Code Duplication · Edited copy of a member (26 corresponding lines) src/llamafactory/data/template.py
Code Duplication · Edited copy of a member (14 corresponding lines) src/llamafactory/train/trainer_utils.py
Code Duplication · Edited copies of one member (3 members, 16+ corresponding lines) src/llamafactory/data/tool_utils.py
Code Duplication · Edited copy of a member (19 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/npu_fused_moe.py
Code Duplication · Edited copy of a member (19 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py
Code Duplication · Edited copy of a member (28 corresponding lines) src/llamafactory/v1/plugins/trainer_plugins/batching.py
Code Duplication · Edited copy of a member (14 corresponding lines) src/llamafactory/data/tool_utils.py
Code Duplication · Edited copy of a member (28 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py
Code Duplication · Edited copy of a member (9 corresponding lines) scripts/bench_qwen.py
Code Duplication · Edited copies of one member (3 members, 25+ corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/npu_fused_moe.py
Code Duplication · Edited copy of a member (17 corresponding lines) src/llamafactory/data/mm_plugin.py
Code Duplication · Edited copy of a member (18 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/rms_norm/npu_rms_norm.py
Code Duplication · Edited copy of a member (17 corresponding lines) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py
Code Duplication · Edited copies of one member (3 members, 13+ corresponding lines) src/llamafactory/v1/trainers/dpo_trainer.py
Code Duplication · Edited copy of a member (16 corresponding lines) src/llamafactory/v1/trainers/dpo_trainer.py
Code Duplication · Edited copies of one member (3 members, 4+ corresponding lines) src/llamafactory/data/processor/feedback.py
Code Duplication · Edited copy of a member (19 corresponding lines) src/llamafactory/chat/hf_engine.py
Code Duplication · Edited copy of a member (10 corresponding lines) src/llamafactory/data/mm_plugin.py
Code Duplication · Edited copy of a member (6 corresponding lines) src/llamafactory/train/dpo/trainer.py
Code Duplication · Edited copy of a member (11 corresponding lines) src/llamafactory/v1/plugins/trainer_plugins/batching.py
Code Duplication · Edited copy of a member (6 corresponding lines) src/llamafactory/chat/vllm_engine.py
Code Duplication · Edited copy of a member (3 corresponding lines) src/llamafactory/hparams/finetuning_args.py
Code Duplication · Edited copies of one member (5 members, 3+ corresponding lines) src/llamafactory/train/dpo/trainer.py
Code Duplication · Edited copy of a member (3 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/liger_kernel_ops.py
Code Duplication · Edited copies of one member (5 members, 4+ corresponding lines) src/llamafactory/train/dpo/trainer.py
We compare every finding with the previous survey's. A finding that has only moved to another line in the same file counts as the same finding, so only new findings appear here. Advisory notes from the AI model are left out, because the model words them afresh in every survey.
Fixed since the last survey: 26 findings
These 26 critical or serious findings were in the previous survey, on 25 October 2026, and are gone from this one.
€17,000 to €85,000, for 282 to 893 hours of work, about 0.3 person-years for one engineer
Difficulty of the problem
Standard, judged from the kind of software and how it is built. Code that solves a harder problem, such as payments or medical bookings, costs more per line to write.
Quality factor
×0.7 at a score of 52. Better code takes more work to write, so the factor is ×1.0 at a score of 70, lower below it and higher above it.
Size
Medium: 45,085 lines of product code
What it is not
Not a quotation: nobody has offered to build it for that. Not a valuation: it says nothing about what the business is worth. Not a certified figure: no professional has signed it as one.
How the estimate is made: We price the hours a team would need to write this code again, at €60 to €95 an hour. Declarations and boilerplate are priced at a fast rate and logic at a slower one, and the logic is then multiplied by the difficulty of the problem and by the quality factor. The estimate can be about 30% off either way, and it moves most with the hourly rate and the difficulty. For this code, every line is priced as straight logic, which keeps the estimate on the low side.
Top priorities
The three actions that raise the score most for the work they take. The full ranked list is in the Roadmap.
1
Add a SAST step to CI running what this repository's stack ships: bandit, `semgrep --config=p/python`, or CodeQL's python pack — so a security regression fails the build instead of landing.
Pass `timeout=` on every `requests`/`httpx` call (requests has no default and will wait forever), mount an `HTTPAdapter(max_retries=Retry(...))` on shared sessions, and wrap calls to flaky dependencies in `tenacity` retries or a `pybreaker` circuit breaker.
Resolve the 1 No ADRs found finding(s) in ADR Quality — start with pyproject.toml.
Raises the score by about 2 points · Low effort · ADR Quality
Diagnosis: what the measurements show together
Each conclusion below combines several dimensions into one point that no single dimension shows, and lists the measurements it rests on.
Where the investment is most exposed · Value at risk
This code would cost about €51,000 to build again, about 0.3 person-years of work. Its weakest lens is Production Readiness, at 41 (Weak). Production Readiness is about whether the product is ready to run in production and to change without breaking. Because the weakest lens counts most in the score, work on Production Readiness also moves the score most.
Based on: the rebuild estimate · the Production Readiness grade · how much each lens counts
What to do: Start with the Production Readiness actions in Top priorities.
If you do one thing first · First action
Add a SAST step to CI running what this repository's stack ships: bandit, `semgrep --config=p/python`, or CodeQL's python pack — so a security regression fails the build instead of landing. Of all the actions in this report, it raises the score most for the work it takes: about 7 points for medium effort. The next survey will show the change in the score.
Based on: the ranked actions in Top priorities, by score gain and effort
What hard-to-read code costs each year · Cost
Four dimensions measure how easy the code is to work in: two measure how tangled its logic is, one how much of it is copied, and one how well each part sticks to a single job. In this codebase they average 5.5 out of 10. Code at that level is slower to change than clean code, and we estimate the extra work at 6% to 14% on every change. The history of the code shows how much it changes: about 8,153 lines over the last 90 days, which is about 33,065 lines a year. At that pace, the extra work comes to an estimated 5.2 to 31.4 engineer-days a year, and it grows as more code changes.
How this is estimated: The number of changed lines is measured from the history of the code. The rest rests on two assumptions of our own: code scoring 8 out of 10 or more adds no extra work, and each point below 8 adds 2.5% to 5.6% to every change, never less than 2% to 5% and never more than 40% to 60% in all; and an engineer changes 150 to 400 lines in a day. The result is a range for planning, not a measurement.
Based on: Cyclomatic Complexity · Cognitive Complexity · Code Duplication · Cohesion (LCOM4) · the code's change history
What to do: Start with the files listed under Churn × Complexity Hotspots, which change often and are hard to read, because that is where the extra work is paid most often.
Architecture: which parts of the code depend on which
The code is divided into modules, groups of code that each handle one part of the product, and a module depends on another when it uses code from it. The table lists the modules both down the side and across the top, in an order where each module should only use modules listed above it. A number in a cell means the module on that row uses the module in that column, and it counts the pairs of building blocks (types) that connect them. The one thing to look for is a mark above the diagonal line. It means two or more modules use each other in a loop (a dependency cycle), so none of them can be changed, tested or released on its own.
161 modules, with 87 dependencies between them. Every module uses only modules listed above it, so there are no loops.
The table shows the 40 modules with the most connections; 121 more are left out to keep it readable.
Which modules use which. The module on each row uses the module in each column, and the number counts the pairs of types that connect them. A cell above the diagonal is part of a loop.
chat.hf_engine uses chat.base_engine, so a change to chat.base_engine can break chat.hf_engine, while a change to chat.hf_engine can't break chat.base_engine.
Position
Below the diagonal: chat.hf_engine uses a module listed above it, which is the healthy direction.
chat.sglang_engine uses chat.base_engine, so a change to chat.base_engine can break chat.sglang_engine, while a change to chat.sglang_engine can't break chat.base_engine.
Position
Below the diagonal: chat.sglang_engine uses a module listed above it, which is the healthy direction.
chat.vllm_engine uses chat.base_engine, so a change to chat.base_engine can break chat.vllm_engine, while a change to chat.vllm_engine can't break chat.base_engine.
Position
Below the diagonal: chat.vllm_engine uses a module listed above it, which is the healthy direction.
data.processor.feedback uses data.processor.processor_utils, so a change to data.processor.processor_utils can break data.processor.feedback, while a change to data.processor.feedback can't break data.processor.processor_utils.
Position
Below the diagonal: data.processor.feedback uses a module listed above it, which is the healthy direction.
data.processor.pairwise uses data.processor.processor_utils, so a change to data.processor.processor_utils can break data.processor.pairwise, while a change to data.processor.pairwise can't break data.processor.processor_utils.
Position
Below the diagonal: data.processor.pairwise uses a module listed above it, which is the healthy direction.
data.processor.pretrain uses data.processor.processor_utils, so a change to data.processor.processor_utils can break data.processor.pretrain, while a change to data.processor.pretrain can't break data.processor.processor_utils.
Position
Below the diagonal: data.processor.pretrain uses a module listed above it, which is the healthy direction.
v1.accelerator.interface uses v1.accelerator.helper, so a change to v1.accelerator.helper can break v1.accelerator.interface, while a change to v1.accelerator.interface can't break v1.accelerator.helper.
Position
Below the diagonal: v1.accelerator.interface uses a module listed above it, which is the healthy direction.
v1.config.model_args uses v1.config.arg_utils, so a change to v1.config.arg_utils can break v1.config.model_args, while a change to v1.config.model_args can't break v1.config.arg_utils.
Position
Below the diagonal: v1.config.model_args uses a module listed above it, which is the healthy direction.
v1.config.model_args uses v1.utils.types, so a change to v1.utils.types can break v1.config.model_args, while a change to v1.config.model_args can't break v1.utils.types.
Position
Below the diagonal: v1.config.model_args uses a module listed above it, which is the healthy direction.
v1.config.sample_args uses v1.config.arg_utils, so a change to v1.config.arg_utils can break v1.config.sample_args, while a change to v1.config.sample_args can't break v1.config.arg_utils.
Position
Below the diagonal: v1.config.sample_args uses a module listed above it, which is the healthy direction.
v1.config.training_args uses v1.config.arg_utils, so a change to v1.config.arg_utils can break v1.config.training_args, while a change to v1.config.training_args can't break v1.config.arg_utils.
Position
Below the diagonal: v1.config.training_args uses a module listed above it, which is the healthy direction.
v1.core.rendering.rendering uses v1.utils.types, so a change to v1.utils.types can break v1.core.rendering.rendering, while a change to v1.core.rendering.rendering can't break v1.utils.types.
Position
Below the diagonal: v1.core.rendering.rendering uses a module listed above it, which is the healthy direction.
v1.core.utils uses v1.utils.objects, so a change to v1.utils.objects can break v1.core.utils, while a change to v1.core.utils can't break v1.utils.objects.
Position
Below the diagonal: v1.core.utils uses a module listed above it, which is the healthy direction.
v1.plugins.data_plugins.converter uses v1.utils.plugin, so a change to v1.utils.plugin can break v1.plugins.data_plugins.converter, while a change to v1.plugins.data_plugins.converter can't break v1.utils.plugin.
Position
Below the diagonal: v1.plugins.data_plugins.converter uses a module listed above it, which is the healthy direction.
v1.plugins.data_plugins.loader uses v1.utils.plugin, so a change to v1.utils.plugin can break v1.plugins.data_plugins.loader, while a change to v1.plugins.data_plugins.loader can't break v1.utils.plugin.
Position
Below the diagonal: v1.plugins.data_plugins.loader uses a module listed above it, which is the healthy direction.
v1.plugins.data_plugins.loader uses v1.utils.types, so a change to v1.utils.types can break v1.plugins.data_plugins.loader, while a change to v1.plugins.data_plugins.loader can't break v1.utils.types.
Position
Below the diagonal: v1.plugins.data_plugins.loader uses a module listed above it, which is the healthy direction.
v1.plugins.model_plugins.chunk_loss uses v1.utils.plugin, so a change to v1.utils.plugin can break v1.plugins.model_plugins.chunk_loss, while a change to v1.plugins.model_plugins.chunk_loss can't break v1.utils.plugin.
Position
Below the diagonal: v1.plugins.model_plugins.chunk_loss uses a module listed above it, which is the healthy direction.
v1.plugins.model_plugins.chunk_loss uses v1.utils.types, so a change to v1.utils.types can break v1.plugins.model_plugins.chunk_loss, while a change to v1.plugins.model_plugins.chunk_loss can't break v1.utils.types.
Position
Below the diagonal: v1.plugins.model_plugins.chunk_loss uses a module listed above it, which is the healthy direction.
v1.plugins.model_plugins.kernels.base uses v1.utils.plugin, so a change to v1.utils.plugin can break v1.plugins.model_plugins.kernels.base, while a change to v1.plugins.model_plugins.kernels.base can't break v1.utils.plugin.
Position
Below the diagonal: v1.plugins.model_plugins.kernels.base uses a module listed above it, which is the healthy direction.
v1.plugins.model_plugins.parallelization uses v1.utils.types, so a change to v1.utils.types can break v1.plugins.model_plugins.parallelization, while a change to v1.plugins.model_plugins.parallelization can't break v1.utils.types.
Position
Below the diagonal: v1.plugins.model_plugins.parallelization uses a module listed above it, which is the healthy direction.
v1.plugins.trainer_plugins.batching uses v1.utils.objects, so a change to v1.utils.objects can break v1.plugins.trainer_plugins.batching, while a change to v1.plugins.trainer_plugins.batching can't break v1.utils.objects.
Position
Below the diagonal: v1.plugins.trainer_plugins.batching uses a module listed above it, which is the healthy direction.
v1.plugins.trainer_plugins.batching uses v1.utils.plugin, so a change to v1.utils.plugin can break v1.plugins.trainer_plugins.batching, while a change to v1.plugins.trainer_plugins.batching can't break v1.utils.plugin.
Position
Below the diagonal: v1.plugins.trainer_plugins.batching uses a module listed above it, which is the healthy direction.
v1.plugins.trainer_plugins.batching uses v1.utils.types, so a change to v1.utils.types can break v1.plugins.trainer_plugins.batching, while a change to v1.plugins.trainer_plugins.batching can't break v1.utils.types.
Position
Below the diagonal: v1.plugins.trainer_plugins.batching uses a module listed above it, which is the healthy direction.
v1.plugins.trainer_plugins.distributed.interface uses v1.utils.plugin, so a change to v1.utils.plugin can break v1.plugins.trainer_plugins.distributed.interface, while a change to v1.plugins.trainer_plugins.distributed.interface can't break v1.utils.plugin.
Position
Below the diagonal: v1.plugins.trainer_plugins.distributed.interface uses a module listed above it, which is the healthy direction.
v1.core.base_sampler uses v1.config.model_args, so a change to v1.config.model_args can break v1.core.base_sampler, while a change to v1.core.base_sampler can't break v1.config.model_args.
Position
Below the diagonal: v1.core.base_sampler uses a module listed above it, which is the healthy direction.
v1.core.base_sampler uses v1.config.sample_args, so a change to v1.config.sample_args can break v1.core.base_sampler, while a change to v1.core.base_sampler can't break v1.config.sample_args.
Position
Below the diagonal: v1.core.base_sampler uses a module listed above it, which is the healthy direction.
v1.core.base_sampler uses v1.core.rendering.rendering, so a change to v1.core.rendering.rendering can break v1.core.base_sampler, while a change to v1.core.base_sampler can't break v1.core.rendering.rendering.
Position
Below the diagonal: v1.core.base_sampler uses a module listed above it, which is the healthy direction.
v1.core.base_trainer uses v1.utils.types, so a change to v1.utils.types can break v1.core.base_trainer, while a change to v1.core.base_trainer can't break v1.utils.types.
Position
Below the diagonal: v1.core.base_trainer uses a module listed above it, which is the healthy direction.
v1.core.base_trainer uses v1.config.training_args, so a change to v1.config.training_args can break v1.core.base_trainer, while a change to v1.core.base_trainer can't break v1.config.training_args.
Position
Below the diagonal: v1.core.base_trainer uses a module listed above it, which is the healthy direction.
v1.core.base_trainer uses v1.core.rendering.rendering, so a change to v1.core.rendering.rendering can break v1.core.base_trainer, while a change to v1.core.base_trainer can't break v1.core.rendering.rendering.
Position
Below the diagonal: v1.core.base_trainer uses a module listed above it, which is the healthy direction.
v1.core.utils.batching uses v1.config.arg_utils, so a change to v1.config.arg_utils can break v1.core.utils.batching, while a change to v1.core.utils.batching can't break v1.config.arg_utils.
Position
Below the diagonal: v1.core.utils.batching uses a module listed above it, which is the healthy direction.
v1.core.utils.batching uses v1.core.rendering.rendering, so a change to v1.core.rendering.rendering can break v1.core.utils.batching, while a change to v1.core.utils.batching can't break v1.core.rendering.rendering.
Position
Below the diagonal: v1.core.utils.batching uses a module listed above it, which is the healthy direction.
v1.core.utils.inference_engine uses v1.config.model_args, so a change to v1.config.model_args can break v1.core.utils.inference_engine, while a change to v1.core.utils.inference_engine can't break v1.config.model_args.
Position
Below the diagonal: v1.core.utils.inference_engine uses a module listed above it, which is the healthy direction.
v1.core.utils.inference_engine uses v1.config.sample_args, so a change to v1.config.sample_args can break v1.core.utils.inference_engine, while a change to v1.core.utils.inference_engine can't break v1.config.sample_args.
Position
Below the diagonal: v1.core.utils.inference_engine uses a module listed above it, which is the healthy direction.
v1.core.utils.inference_engine uses v1.core.rendering.rendering, so a change to v1.core.rendering.rendering can break v1.core.utils.inference_engine, while a change to v1.core.utils.inference_engine can't break v1.core.rendering.rendering.
Position
Below the diagonal: v1.core.utils.inference_engine uses a module listed above it, which is the healthy direction.
v1.plugins.data_plugins uses v1.utils.types, so a change to v1.utils.types can break v1.plugins.data_plugins, while a change to v1.plugins.data_plugins can't break v1.utils.types.
Position
Below the diagonal: v1.plugins.data_plugins uses a module listed above it, which is the healthy direction.
v1.plugins.data_plugins uses v1.plugins.data_plugins.converter, so a change to v1.plugins.data_plugins.converter can break v1.plugins.data_plugins, while a change to v1.plugins.data_plugins can't break v1.plugins.data_plugins.converter.
Position
Below the diagonal: v1.plugins.data_plugins uses a module listed above it, which is the healthy direction.
v1.plugins.trainer_plugins.distributed.fsdpturbo uses v1.accelerator.interface, so a change to v1.accelerator.interface can break v1.plugins.trainer_plugins.distributed.fsdpturbo, while a change to v1.plugins.trainer_plugins.distributed.fsdpturbo can't break v1.accelerator.interface.
Position
Below the diagonal: v1.plugins.trainer_plugins.distributed.fsdpturbo uses a module listed above it, which is the healthy direction.
v1.utils.callbacks.trainer_callback uses v1.config.training_args, so a change to v1.config.training_args can break v1.utils.callbacks.trainer_callback, while a change to v1.utils.callbacks.trainer_callback can't break v1.config.training_args.
Position
Below the diagonal: v1.utils.callbacks.trainer_callback uses a module listed above it, which is the healthy direction.
v1.samplers.cli_sampler uses v1.config.model_args, so a change to v1.config.model_args can break v1.samplers.cli_sampler, while a change to v1.samplers.cli_sampler can't break v1.config.model_args.
Position
Below the diagonal: v1.samplers.cli_sampler uses a module listed above it, which is the healthy direction.
v1.samplers.cli_sampler uses v1.config.sample_args, so a change to v1.config.sample_args can break v1.samplers.cli_sampler, while a change to v1.samplers.cli_sampler can't break v1.config.sample_args.
Position
Below the diagonal: v1.samplers.cli_sampler uses a module listed above it, which is the healthy direction.
v1.samplers.cli_sampler uses v1.core.rendering.rendering, so a change to v1.core.rendering.rendering can break v1.samplers.cli_sampler, while a change to v1.samplers.cli_sampler can't break v1.core.rendering.rendering.
Position
Below the diagonal: v1.samplers.cli_sampler uses a module listed above it, which is the healthy direction.
v1.samplers.cli_sampler uses v1.core.base_sampler, so a change to v1.core.base_sampler can break v1.samplers.cli_sampler, while a change to v1.samplers.cli_sampler can't break v1.core.base_sampler.
Position
Below the diagonal: v1.samplers.cli_sampler uses a module listed above it, which is the healthy direction.
v1.trainers.dpo_trainer uses v1.utils.types, so a change to v1.utils.types can break v1.trainers.dpo_trainer, while a change to v1.trainers.dpo_trainer can't break v1.utils.types.
Position
Below the diagonal: v1.trainers.dpo_trainer uses a module listed above it, which is the healthy direction.
v1.trainers.dpo_trainer uses v1.config.training_args, so a change to v1.config.training_args can break v1.trainers.dpo_trainer, while a change to v1.trainers.dpo_trainer can't break v1.config.training_args.
Position
Below the diagonal: v1.trainers.dpo_trainer uses a module listed above it, which is the healthy direction.
v1.trainers.dpo_trainer uses v1.core.base_trainer, so a change to v1.core.base_trainer can break v1.trainers.dpo_trainer, while a change to v1.trainers.dpo_trainer can't break v1.core.base_trainer.
Position
Below the diagonal: v1.trainers.dpo_trainer uses a module listed above it, which is the healthy direction.
v1.trainers.rm_trainer uses v1.utils.types, so a change to v1.utils.types can break v1.trainers.rm_trainer, while a change to v1.trainers.rm_trainer can't break v1.utils.types.
Position
Below the diagonal: v1.trainers.rm_trainer uses a module listed above it, which is the healthy direction.
v1.trainers.rm_trainer uses v1.config.training_args, so a change to v1.config.training_args can break v1.trainers.rm_trainer, while a change to v1.trainers.rm_trainer can't break v1.config.training_args.
Position
Below the diagonal: v1.trainers.rm_trainer uses a module listed above it, which is the healthy direction.
v1.trainers.rm_trainer uses v1.core.base_trainer, so a change to v1.core.base_trainer can break v1.trainers.rm_trainer, while a change to v1.trainers.rm_trainer can't break v1.core.base_trainer.
Position
Below the diagonal: v1.trainers.rm_trainer uses a module listed above it, which is the healthy direction.
v1.trainers.sft_trainer uses v1.utils.types, so a change to v1.utils.types can break v1.trainers.sft_trainer, while a change to v1.trainers.sft_trainer can't break v1.utils.types.
Position
Below the diagonal: v1.trainers.sft_trainer uses a module listed above it, which is the healthy direction.
v1.trainers.sft_trainer uses v1.config.training_args, so a change to v1.config.training_args can break v1.trainers.sft_trainer, while a change to v1.trainers.sft_trainer can't break v1.config.training_args.
Position
Below the diagonal: v1.trainers.sft_trainer uses a module listed above it, which is the healthy direction.
v1.trainers.sft_trainer uses v1.core.rendering.rendering, so a change to v1.core.rendering.rendering can break v1.trainers.sft_trainer, while a change to v1.trainers.sft_trainer can't break v1.core.rendering.rendering.
Position
Below the diagonal: v1.trainers.sft_trainer uses a module listed above it, which is the healthy direction.
v1.trainers.sft_trainer uses v1.core.base_trainer, so a change to v1.core.base_trainer can break v1.trainers.sft_trainer, while a change to v1.trainers.sft_trainer can't break v1.core.base_trainer.
Position
Below the diagonal: v1.trainers.sft_trainer uses a module listed above it, which is the healthy direction.
v1.utils.callbacks.logging_callback uses v1.config.training_args, so a change to v1.config.training_args can break v1.utils.callbacks.logging_callback, while a change to v1.utils.callbacks.logging_callback can't break v1.config.training_args.
Position
Below the diagonal: v1.utils.callbacks.logging_callback uses a module listed above it, which is the healthy direction.
v1.utils.callbacks.logging_callback uses v1.utils.callbacks.trainer_callback, so a change to v1.utils.callbacks.trainer_callback can break v1.utils.callbacks.logging_callback, while a change to v1.utils.callbacks.logging_callback can't break v1.utils.callbacks.trainer_callback.
Position
Below the diagonal: v1.utils.callbacks.logging_callback uses a module listed above it, which is the healthy direction.
At a glance — Code Health · 53% · Adequate · gated by D1, D2, X4 ·
Findings mapped to OWASP categories; the specific CVEs/secrets are in the Security dimension cards below and findings.md (redacted only on the public version of this report).
OWASP category
Findings
Severity
A02:2025 — Security Misconfiguration
56
High / Critical
A05:2025 — Injection
41
High / Critical
A03:2025 — Software Supply Chain Failures
9
Medium
Roadmap
Top priorities: Add a SAST step to CI running what this repository's stack ships: bandit, `semgrep --config=p/python`, or CodeQL's python pack — so a security regression fails the build instead of landing; Pass `timeout=` on every `requests`/`httpx` call (requests has no default and will wait forever), mount an `HTTPAdapter(max_retries=Retry(...))` on shared sessions, and wrap calls to flaky dependencies in `tenacity` retries or a `pybreaker` circuit breaker; Interpolated log message defeats structured logging.
Ranked by impact ÷ effort. "Helps" is the estimated gain on the 0–100 health score.
Do this
Helps
Effort
Dimension
Add a SAST step to CI running what this repository's stack ships: bandit, `semgrep --config=p/python`, or CodeQL's python pack — so a security regression fails the build instead of landing.
Pass `timeout=` on every `requests`/`httpx` call (requests has no default and will wait forever), mount an `HTTPAdapter(max_retries=Retry(...))` on shared sessions, and wrap calls to flaky dependencies in `tenacity` retries or a `pybreaker` circuit breaker.
Add a `healthcheck:` to the served compose service — probing the endpoint it already answers on where it has one — with `depends_on: condition: service_healthy` on whatever waits for it, and keep the deployed image tag immutable and recorded so rolling back is re-pointing at the previous tag rather than rebuilding.
Every finding carries one of four grades. Three say how serious it is. The fourth says this
survey could not settle it — and it is a grade, not a gap.
Critical — 56
A definite problem that already costs you something and drags the score down: a
missing authorisation check, a dependency with a known exploit, a build that does not reproduce. Failure here
tends to cause failures elsewhere.
Serious — 459
Likely wrong, but not failing yet. It degrades
the codebase over a longer horizon and can cause failures elsewhere — not urgent this week, not something to
carry for two years either.
Minor — 64
Recorded, with no effect on how the codebase functions.
Present so the survey is complete, not because it needs doing.
Could not be resolved — 14
Something this survey could not settle
from the outside, and which could be critical or serious. Either a control was required and no
positive evidence of it exists in the repository — a backup job that nothing shows was ever restored from proves
nothing about restores — or our own analysis could not run over that part of the tree. This is not a clean
result. These are excluded from the score rather than awarded a pass, so the number on the cover neither
rewards nor penalises them: if you act on this survey without resolving them, you carry that risk yourself. Each
one is named under Limitations.
Methodology & how to trust this report
This survey is a deep, periodic assessment — run each sprint, monthly, or quarterly, taking the time to go wider and deeper than a quick check and surfacing in one coherent report what you'd otherwise piece together from a dozen separate tools. It scores deterministically: the same commit yields the same score, every run. All 51 evaluated dimensions are computed by tools and static analysis; no language model sets or judges any of them. Overall confidence is 0.9, the weighted average across measured dimensions.
Every figure here is one of two kinds, and we label which: ✓ Measured — a deterministic fact (LoC, complexity, coverage); ~ Modeled — an estimate from a stated model (cost, effort, value-at-risk), always a range with its assumptions, never a precise fact. We never present a modelled estimate as if it were measured. Perfect or absent scores carry their provenance too (ADR-0011): ✓ Tool-verified means the property itself was measured across the surface; ○ Nothing flagged means the probes came back clean — a claim bounded by what a repository can show; ⊘ Not evidenced means a working control (a tested restore, an automated rollback) showed no positive evidence — absence of evidence is not evidence of a control, so it's excluded from the score rather than awarded a spurious 10.
What we checked — 51 dimensions across the health lenses
Each chip is a dimension scored from real signals across architecture, testing, dependencies, security & compliance, documentation, git-history and code quality — in one coherent pass. A surface report typically covers a handful.
How to trust any code-health report — three questions
Can you open the finding? Real findings cite a repo-relative file and line you can open at the cited line — never an absolute scratch path. Here, 566 of 579 do; the remainder are repo-wide signals — a dimension-level measurement, not a single line. (Every path in this report is repo-relative by construction: paths are normalized at the producer and the report is rejected if any rooted path leaks through.)
Is there a tool behind the number? Every score below names the method that produced it: Roslyn, git or a scanner, not a narrative.
Does re-running give the same result? Run it again on the same commit and the score — and this report, byte for byte — is identical. A report whose numbers move between runs is describing the run, not the code.
This report answers yes to all three. That's the bar to hold any assessment to.
Tools & methods
The actual versions used this run (captured at analysis time) — re-run on the same commit for the identical score.
Method
Backs
Version
Evaluator
Roslyn static analysis
Complexity, cohesion, coupling, dead code, API surface, layering
What ran differently this time — a tool absent, degraded, or that fell back to an estimate. Named openly, not folded silently into the scores. A degraded run also records its exact cause in diagnostics.md.
D8 Code Coverage — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. Coverage NOT MEASURED: test source is present (.py) but the built-in coverage collector has no runner for this repository's ecosystem — so this suite was never executed by it. Not scored — this is a gap in the analyzer's language coverage, not a defect in the repo.
D11 Test Reliability — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. Test source is present (.py) and this repository declares a Python test suite (repository root, 58 test files), but it was not re-run: its dependency install outgrew the 6 GB scratch ceiling (6.672 GB measured) and was stopped; its suite was not run. Not scored — this is a gap in the analyzer's language coverage, not a finding about this repository.
D12 Dependency Hygiene — not measured this run — This is a true statement about the repository that carries nothing for its owner to act on, so it is reported here rather than as a defect in their code. This repository's 31 shipped Python distribution(s) across 2 manifest(s) WERE read; what went unanswered is the currency half, because it grades an EXACT pin against the newest release and every declaration here is a floor or a range — which installs the newest release it admits and so cannot be behind one. So pypi.org was never asked. This is a true statement about the repository, and the healthy one, NOT a gap on our side: no reader we could write would find a currency question here.
D19 Documentation Quality — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. Each ecosystem's manifests (what makes a folder runnable or a published package) need their own proof before D19 judges its units. Until then those folders' READMEs are judged only as documents (boilerplate, structure), never counted as complete.
D21 Naming Consistency — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. PREREGISTRATION version 20's fallback (adjudication D21-sample3-v3): this rule kind was adjudicated below the 95 % precision gate, so its candidates are counted here and not published, and the score covers only the acronym-spelling and awaitable-suffix rules. The kind returns as rows only after it shows a measured precision; this says nothing about whether these names are consistent.
D22 Internal API Consistency — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. D22's deterministic call-shape rules are gated on C# first (docs/plans/deterministic-engine.md, P5): each other language is switched on only after its own concept suite and A/B gate pass. This says nothing about whether that surface is consistent.
D24 Comment Value — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. Each source language's comment syntax, and the code a comment annotates in it, needs its own proof before D24 judges it. Until then those comments are left unread, not counted as clean.
AX1 Captive dependencies — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads Microsoft.Extensions.DependencyInjection registrations in C# and Spring beans in Java/Kotlin only, and this repository defines its own container in src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py, whose lifetimes are not modelled yet, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
AX6 Interface segregation — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check is computed over the public interfaces this run's compilations declare, and none was loaded, so it had nothing to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
AXR1 Runtime accessibility — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. Render strategy: boot via DockerCompose (REDACTED). compose up failed (exit 17 — an image could not be built) — llamafactory Pulling llamafactory Warning pull access denied for llamafactory, repository does not exist or may require 'docker login': denied: requested access to the resource is denied failed to solve: failed to register layer: write /opt/intel/oneapi/debugger/2026.1/opt/debugger/src/dependencies.tar.gz: no space left on device; runtime evidence skipped.
C1 Data Protection — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. These personal data controls are read from declarative annotations, request middleware, entity/column names and guard methods in a C# source model, and none was loaded on this run, so there was nothing to gather. That is a gap in this analyzer's language reach — not a finding that the repository lacks personal data controls.
GD1 Unfinished & placeholder code — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads C# syntax, F#, JavaScript/TypeScript, Dart, Ruby and Scala source only, and this repository's Python is most of its product and is not read yet, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
IC1 Incompleteness & stubs — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads C# syntax, JavaScript/TypeScript, Java, Dart, Ruby and Scala source only, and this repository's Python is most of its product and is not read yet, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
M4 Documentation accuracy — measured, with a gap in what it reached — We measured this, but not all of it. What we did not reach is a gap on our side — a collector, parser or image we have not built yet — so the numbers on that dimension cover less than the repository, and the part left out is not evidence that it would have passed. M4 checks only the claim kinds adjudicated at or above 95 % precision: links and versions (PREREGISTRATION version 9), and artefact counts an order of magnitude off. Paths, command arguments, installs, environment variables, settings, projects, packages, routes, cd targets, infrastructure products and removed modules are read but not checked, and none of them is reported or counted.
P5 DR & Backup — not measured this run — This is a true statement about the repository that carries nothing for its owner to act on, so it is reported here rather than as a defect in their code. No backup/snapshot/replication config, RTO/RPO or restore-procedure documentation was found — and no production persistence was detected either (no data-access packages, no data-store services, no database resources), so there is nothing in this repository whose loss a DR control would recover. If this system's data lives in a platform or ops repo we can't see, that's where the DR evidence belongs.
S1 Web-Security Posture — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. These web-security controls are read from declarative annotations, request middleware, entity/column names and guard methods in a C# source model, and none was loaded on this run, so there was nothing to gather. That is a gap in this analyzer's language reach — not a finding that the repository lacks web-security controls.
X16 Unfloored truncation loop — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check's reader does not cover most of the languages this repository's product is written in. What it read is kept, but it is too small a share to grade the product by. That is a gap in this analyzer's language reach — not a finding about this repository.
X5 Nullable reference types — not measured this run — We could not measure this here. That is a gap on our side — a collector, parser or image we have not built yet — and it is neither a defect in this repository nor evidence that the check would have passed. This check reads C# syntax and MSBuild project configuration, TypeScript source and its tsconfig files, Java source and its package and module declarations, PHP source and its PHPStan and Psalm configuration, Dart source and its pubspec language version, Ruby source and its Sorbet and Steep configuration, Scala source and its build's explicit-nulls, WartRemover and Scalafix settings, and Kotlin source only, and no C# was loaded, no TypeScript was found, and this repository's Python is not read yet, so it had nothing of this repository's product to read. That is a gap in this analyzer's language reach — not a finding that the repository is free of what this check looks for.
Repo exclusion declarations (.gitattributes linguist-generated/vendored, .editorconfig generated_code): none declared — every source file was scored.
Limitations & what we did not check
We assess the repository exactly as committed, and only the repository. By design we do not reach outside the source tree: the live cloud account, the running CI/CD pipeline, the host's branch-protection and approval rules, the production configuration, or a restore actually exercised against a backup are all out of scope. That boundary is a feature, not a gap — a repo-relative, deterministic scan re-runs identically on any commit and every finding opens at a real file and line, where a live audit can neither be reproduced nor traced. The visible consequence is that controls which leave no in-repo evidence are reported as "not evidenced" and excluded from the score rather than awarded a number a static scan cannot justify.
Per-dimension blind spots
For each dimension that was measured, what a static, repo-only scan structurally cannot see — the honest edge of the measurement, not a failure of it.
D1 Cyclomatic Complexity: Cyclomatic complexity counts branches statically — it cannot tell an essential decision tree from accidental tangle, nor see complexity that lives in data or configuration (large switch-case token tables, DSL lexers/parsers, data-as-code rule tables) rather than control flow: a tokenizer's many single-character cases read as high complexity though each branch is trivial.
D2 Cognitive Complexity: Cognitive-complexity heuristics approximate how hard code is to follow; genuine domain difficulty and well-named intent that eases reading are not captured.
D3 God Classes: "God class" is sized by members and responsibilities visible in the type — a deliberately broad facade over a coherent subsystem can read the same as an accidental grab-bag. For front-end JS the file-length check is cohesion-aware (a single-responsibility module — one class/IIFE — earns a 3× threshold), but cohesion is approximated from top-level declarations, not true dependency structure.
D4 Code Duplication: Duplication is token-similarity — an in-process token-stream comparison over sliding windows, with type-aware normalization — so it finds copy-paste, not semantic duplication expressed differently. Committed machine-written code (scaffolded migrations, designer/codegen output, protobuf/OpenAPI stubs, model snapshots) is EXCLUDED — its repetition is the tool's, not the team's — so the score reflects hand-written duplication only.
D6 Cohesion (LCOM4): LCOM4 cohesion is syntactic — it infers connectivity from which methods touch which fields/methods by name, not from real runtime behaviour or intent.
D13 Secret Scanning: Secret detection is signature- and entropy-based on the current tree — a secret that does not match a known pattern, or one already rotated, will not be flagged (a clean scan is "nothing matched", not "no secrets exist").
D14 License Compliance: License compatibility is checked against declared package metadata and a policy — mislabelled or missing license metadata, and obligations that depend on how you distribute, are not resolved here.
D15 Churn × Complexity Hotspots: Churn hotspots come from git history — a freshly imported or squashed repository has no churn signal, and recent rewrites can mask a historically risky file.
D16 Bus Factor: Bus-factor is a time-decayed model of commit attribution (who has recently, repeatedly worked a file), not comprehension — pairing, review and reading-without-committing spread knowledge it can't see; bot commits and shared accounts still distort it.
D17 Explicit Debt: Acknowledged-debt signals (TODO/FIXME, suppressions, dead code) are textual — undocumented debt that nobody marked, and debt that lives in design rather than annotations, is invisible. Committed machine-written code (scaffolded migrations, designer/codegen output, generated stubs) is excluded — it is never the team's dead code to delete.
D19 Documentation Quality: Documentation quality publishes two things only: a runnable or packaged unit with no example, and a multi-project root README that maps none of its parts. It does not judge clarity, and its other checks (overview, licence, boilerplate, structure, empty sections, XML-doc coverage) are withheld after adjudication: their candidates are counted in the card's gaps, not shown as rows. A false statement in a document is M4's; units are .NET projects only.
D20 ADR Quality: ADR quality checks the structure of the decision records present: it cannot know about decisions made and never recorded, and it does not judge how well a record argues its case. Records in a language the section lexicon does not cover are not evaluated.
D26 Project Cohesion: Project focus is sized from members/namespaces per project — a project that is broad by deliberate design reads the same as one that has sprawled.
D27 Navigability: Indirection/navigability is structural — it measures hops to follow a call, not whether that indirection buys real flexibility or just ceremony.
D28 Secrets (history): Secret-history scanning sweeps the git log for known patterns — a secret that predates the available history, or never matched a signature, is not found (clean means "nothing matched in the history we can see").
D29 Static Analysis (SAST): SAST findings are pattern-based (semgrep) — it finds classes of bug it has rules for; logic flaws, auth/authorization gaps and issues needing runtime context are out of reach (and clean means "no rule matched").
D30 Dependency Vulnerabilities: CVE matching depends on accurate package/version metadata and on the advisory databases — a vulnerability with no published advisory, or in code not declared as a dependency, is not seen. Coverage needs a RESOLVED graph: an unpinned requirements.txt, or a pom without a resolved build, yields partial coverage rather than a clean verdict. An ecosystem the analyzer cannot scan is reported as unmeasured, never as clean.
D31 IaC & Container Security: IaC scanning checks Dockerfiles/Terraform/Kubernetes against best-practice rules — it cannot see the live cloud account, runtime configuration, or drift between the committed config and what is actually deployed.
D34 Knowledge Freshness: Freshness is decayed commit RECENCY, not comprehension — code read often but rarely committed reads as orphaned, and stable code that genuinely needs no changes is penalised the same as forgotten code; bot/squash commits distort it like the bus factor.
D35 Change Coupling: Change coupling is co-change in COMMITS — files split across separate commits, or coupled only through a shared config/build step, read as uncoupled, and a sweeping commit (rename/format) is excluded so it doesn't couple everything. It shows that files change together, not WHY: a high coupling can be a healthy cohesive pair as readily as a hidden leak.
D43 Malicious Dependencies: Only packages some vulnerability database has already NAMED as malicious are seen — a compromise published in the last hours, or never reported at all, is invisible here, and this dimension reading 10 is not evidence that a dependency is trustworthy. There is no typosquat or dependency-confusion analysis: a package nobody has reported is simply absent from the feeds. Coverage is the dependency scan's: an ecosystem that could not be scanned is disclosed as unmeasured, never as clean.
D44 Platform End-of-Life: The support table is FROZEN, so it goes out of date by losing RECALL: a release that ended support after the table was written is missed until the table is refreshed, and this dimension reading 10 is not evidence that a platform is current. Only platforms the repository DECLARES in a place this pass reads are seen — a runtime named only in a REDACTED (D31's subject), in a CI workflow (D29's), or in a file this pass does not parse (go.mod, a Gemfile ruby directive) is invisible here, which is why a repository declaring none of them abstains rather than scoring. Only frameworks with a PUBLISHED support policy are tracked: React, Flask and Express publish none, so their age cannot be judged and their absence from a report is not a statement that they are supported.
AX10 Code composition: Role is inferred from namespace/folder convention, not semantics — a domain concept living in a folder named "Services" reads as application, and the split is lines-of-code, not business value. The business-logic-share score is a SOFT, FLOORED signal: it contributes to the Architecture lens but is floored at the Critical gate, so an infrastructure-heavy design (a gateway, an ETL, a driver) is legitimately low without being nuked to zero.
M4 Documentation accuracy: Documentation accuracy checks links, versions and artefact counts against the tree: other claims (paths, commands, settings, routes) are read but not checked, and it cannot run the onboarding or measure how long a real new joiner takes.
P4 Deployment & Rollback: Approval/branch-protection rules live in repository settings the scan cannot see — only their in-repo evidence (config files, workflows) is checked, so a control enforced purely in the host's settings reads as "not evidenced".
P6 Release Hygiene: Rollback/observability controls are inferred from repo artefacts (pipelines, dashboards-as-code) — controls configured in external tooling, with no in-repo trace, cannot be credited.
What it measures: How tangled the control flow is — methods with many branches are hard to test and change.
Method: Cyclomatic complexity per method (1 + decision points), computed exhaustively across production source; test projects separated by convention. Deterministic.
+ 57 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Bring the 1 body over 60 down to 60 or less in Cyclomatic Complexity — start with parser.get_train_args (cyclomatic 112). — Refactoring it lifts Cyclomatic Complexity from 3.9 to about 5.2/10.
Detailed fixes: d1_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: How hard the code is for a person to follow, beyond raw branching.
Method: Cognitive complexity per method (Sonar-style nesting-penalized score), computed exhaustively over production code, excluding test projects. Deterministic.
+ 109 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Bring the 4 bodies over 60 down to 60 or less in Cognitive Complexity — start with parser.get_train_args (cognitive 137), adapter._setup_lora_tuning (cognitive 101), Qwen2OmniPlugin.process_messages (cognitive 67). — This score is capped by its worst body, so a finding fixed alone moves it by almost nothing — the next one down takes its place. Refactoring these 4 together lifts Cognitive Complexity from 2.0 to about 3.2/10, projected with the scoring formula itself and assuming each lands exactly at 60; a cleaner split scores higher.
Detailed fixes: d2_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D3 · God Classes9.3 / 10Stronggated by 7 serious findings✓ Tool-verified
What it measures: Over-large classes that try to do too much ("god classes").
Method: God-class detection by line and method-count thresholds per logical type (partial classes unified), filtered for generated code and registration/contract false positives. Deterministic.
Resolve the 7 FileTooLong finding(s) in God Classes — start with mm_plugin.py, constants.py, template.py. — One of this dimension's main actionable groups (7 warning-level).
Detailed fixes: d3_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: How much of the production code is copy-pasted: the share of production lines inside a reported copy (every copy of a duplicated block or of an edited member, each line once), 10 at none and 0 at a quarter of the lines.
Method: Code duplication via token-stream sliding windows with type-aware normalization (locals masked, type names preserved), scored on the share of production lines inside a reported copy (each line once; 10 at none, 0 at a quarter). Deterministic.
120 duplicated block group(s) detected. 8.4 % of the production lines (3,784 of 45,085) are in a reported copy. A further 46 rows report members as variants of one another; the share counts each copied line once, however many rows cite it. 7 of the 166 are in trees this repository does not ship — vendored, example/demo, project-template, fixture and benchmark code — and are ranked below the shipped groups rather than excluded from them: the duplication there is real and is still counted in this dimension's score. The dimensions that publish a production-file census leave those trees out of theirs, so this count is deliberately drawn over the wider population.
+ 104 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 7 Duplicated block (8 lines × 2) finding(s) in Code Duplication — start with converter.py, mm_plugin.py, tool_utils.py. — One of this dimension's main actionable groups (7 warning-level).
Resolve the 7 Duplicated block (6 lines × 2) finding(s) in Code Duplication — start with chatter.py, eval_bleu_rouge.py, api.py. — One of this dimension's main actionable groups (7 warning-level).
Resolve the 6 Duplicated block (9 lines × 2) finding(s) in Code Duplication — start with converter.py (2), patcher.py, workflow.py. — One of this dimension's main actionable groups (6 warning-level).
Detailed fixes: d4_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether a class's methods are focused on a single responsibility.
Method: LCOM4 cohesion per production class with at least two methods: connected components of methods sharing state or calls, computed syntactically. Deterministic, not a proxy.
Coverage: Exhaustive · type-level: LCOM4 cohesion computed over every production class — the population is all types, not a name convention.
Resolve the 2 Low cohesion finding(s) in Cohesion (LCOM4) — start with trainer.py (2). — One of this dimension's main actionable groups (2 warning-level).
Detailed fixes: d6_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether any secrets (keys, tokens, passwords) have leaked into the code.
Method: In-process native secret scanner (entropy plus signature patterns) across all tracked files; no external tool. A clean result is a measured 10, not no-data zero. Deterministic.
Secret scan ran and found no leaked secrets. 7 detection(s) were excluded as holding no minted credential in material that runs: a name, reference or comparison rather than a value, a readable phrase or pattern, a value that declares itself fake, or development, test, example, mock or demo material.
What it measures: Whether the licenses of third-party packages are compatible with your policy.
Method: Third-party package licenses resolved from declared package metadata and checked against the configured policy (allow/deny/copyleft). Deterministic; clean = no incompatible license found at metadata depth.
0 of 121 shipped Python distribution(s) use a banned license. Licences were resolved from PyPI over the distributions a consumer installs — this repository's 31 declared runtime requirement(s) closed transitively over each distribution's published `requires_dist` (90 reached that way). Requirements it states ONLY under an extra, a PEP 735 dependency group, a Poetry dev group or a dev-named requirements file are excluded: pip does not install any of them for a consumer. ★ This repository commits no dependency lockfile that this pass reads, so each licence is the one PyPI publishes for the distribution's CURRENT release rather than for a pinned version. 16 of them publish no licence on PyPI this pass can read; that is missing data, not a violation, and none of them is charged. This repository publishes itself under Apache-2.0, which is its own choice and is not judged here.
What it measures: Files that change often and are also complex — the riskiest hotspots.
Method: Per production file churn times cyclomatic complexity over a rolling window, computed from git and Roslyn/JS/Razor analysis. Exhaustive, deterministic per commit date.
Resolve the 7 Hotspot finding(s) in Churn × Complexity Hotspots — start with patcher.py, liger_kernel.py, fsdpturbo.py. — One of this dimension's main actionable groups (7 warning-level).
Detailed fixes: d15_recommendation.md · top locations in Appendix A, every location in findings.md.
Do you agree with this assessment?
D16 · Bus Factor9.7 / 10Exemplary✓ Tool-verified
What it measures: Whether knowledge is concentrated in too few people (the "bus factor").
Method: Living knowledge per author via time-decayed commit attribution (6-month half-life, focus weighting) across largest source files. Deterministic, avoids blame's mechanical-refactor false positives.
5 source file(s) have their living knowledge concentrated in one author (≥90% of recent, decayed contribution). The largest is src/llamafactory/train/mca/workflow.py. Counted over 170 of the 242 production source files in this repository: the rest are under the ~2,400-byte size floor this dimension measures over.
Off-boarding risk: anonymized user #1
Further sole-owners (lower concentration)
✓ On the Gold path — maintain.
Detailed fixes: d16_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Acknowledged debt left in the code — TODOs, dead code, suppressed warnings.
Method: Roslyn syntactic debt markers (suppressions/TODO/FIXME/HACK/empty-catch/commented-code/Obsolete) plus SymbolFinder dead-code analysis; weighted-debt-per-KLoC density deducted 2.0x per unit. Deterministic, exhaustive.
20 deducted task-comment markers across 45085 LoC (0.0/KLoC) → score 9.9. Task comments only: this repository's language is read without a compiler, so D17's suppression, dead-code and commented-out-code arms did not run and this score counts fewer marker kinds than a .NET repository's would.
Resolve the 11 TodoComment finding(s) in Explicit Debt — start with peft.py (2), ulysses.py (2), test_sglang.py. — One of this dimension's main actionable groups (11 warning-level).
Resolve the 5 HackComment finding(s) in Explicit Debt — start with trainer.py (2), workflow.py, loader.py. — One of this dimension's main actionable groups (5 warning-level).
Resolve the 4 FixmeComment finding(s) in Explicit Debt — start with collator.py (4). — One of this dimension's main actionable groups (4 warning-level).
Detailed fixes: d17_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether the project's documentation is clear, complete, and useful.
Method: Every README, docs/ document and root guide parsed by its markup and measured in Unicode letters. Published: a runnable or packaged .NET project whose README (or a document it links, or a root guide) shows no example, and a root README naming none of three or more projects. Overview, licence, boilerplate, wall-of-text, empty-section and XML-doc rows are measured and withheld (counted in gaps) after adjudication. Deterministic, exhaustive, advisory.
1 of 1 documentation facets pass in full. 71 document(s) read across 1 unit(s).
✓ On the Gold path — maintain.
Detailed fixes: d19_recommendation.md.
Do you agree with this assessment?
D20 · ADR Quality0.0 / 10Critical✓ Tool-verified
What it measures: Whether architecture decisions are recorded well (context, decision, consequences).
Method: Every ADR read by its section structure: nine located rules (a missing Decision, Context or Consequences section, a stale status, two records deciding the same question, a dangling supersede link, a number-only title, a single option, no named cost, no status where the log uses one, no enforcement field where the log adopted one), each a fixed deduction from 10; the score is the mean over evaluated records. Deterministic, no model. Advisory.
Resolve the 1 No ADRs found finding(s) in ADR Quality — start with pyproject.toml. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d20_recommendation.md · top locations in Appendix A, every location in findings.md.
1 of 2 build units (Python) flagged as possibly oversized/incoherent.
Projects may be oversized for their cohesion
What to do
Resolve the 1 Projects may be oversized for their cohesion finding(s) in Project Cohesion. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d26_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: How far you must trace to follow a call — low indirection and co-located slices read easier.
Method: Call indirection (interface hops, cross-namespace calls, slice-locality scaled) over a sampled set of method invocations, size-aware baseline. Sampled; confidence discounted by symbol-resolution gaps. C# also names each pass-through layer (a class whose every public method only forwards its own parameters to one collaborator) as a located finding; the score is not affected.
Coverage: Slice locality from the first namespace segments, SAMPLED (≤400 methods) — not exhaustive.
57 % of calls cross a namespace and 0 % go through an interface, but 100 % of collaborators are co-located — so a call's collaborators sit together and tracing stays easy. Baseline: small — navigation cost is tolerated.
What it measures: Whether any secrets were ever committed — scanned across the full git history, not just now.
Method: Secret scan via TWO gitleaks detect passes in an isolated checkout — the full git history, then a second --no-git pass over the working tree as it stands — merged and de-duplicated by (rule, file, line); each match flagged High. Both invocations are recorded in the audit trail. Exhaustive; when the tool is absent, or when its output cannot be parsed into the expected shape, the dimension is WITHHELD as an explicit measurement gap on our side — unscored and excluded from the lens, never a hedged middling score.
What it measures: Real static-analysis (SAST) findings — likely security bugs in the code, any language.
Method: Polyglot static analysis via semgrep across the repo using the pinned, image-baked p/security-audit + p/owasp-top-ten rulesets (no scan-time registry fetch); severity rules (ERROR/WARNING/INFO) map to a full-band severity-weighted score. Exhaustive, deterministic; degrades on parse failure.
Coverage: semgrep pattern rules over all files — exhaustive for the rule set, blind to classes of bug without a rule (clean = no rule matched).
41 finding(s): 0 critical, 35 high, 5 medium, 1 low. 26 unpinned-GitHub-Actions row(s) are reported here but scored by D36 (supply-chain provenance), which measures that posture as `pinned_actions` — one pinning decision is charged once, not once per lens. semgrep hit a parse error in 1 file(s) — `src/llamafactory/webui/locales.py` — so no absence of findings in them is evidence of anything, and nothing in them was analysed. Fix the syntax error (or exclude the file deliberately) and re-scan to cover them. Separately, one or more rules could not re-parse an embedded snippet in 1 file(s) (e.g. a workflow `run:` block read as shell). Those files WERE scanned and their other rows are unaffected; only those rules' view of those snippets is missing.
REDACTED
REDACTED
REDACTED
REDACTED
REDACTED
+ 2 more group(s) — more in Appendix A; the complete list is findings.md.
What to do
Resolve the 7 REDACTED finding(s) in Static Analysis (SAST) — start with REDACTED (2), REDACTED, REDACTED. — One of this dimension's main actionable groups (7 issue-level).
Resolve the 1 REDACTED finding(s) in Static Analysis (SAST) — start with REDACTED. — One of this dimension's main actionable groups (1 issue-level).
No action in Static Analysis (SAST) — all 26 REDACTED finding(s) are reported here at file:line but scored by D36 (supply-chain provenance), so none is charged to this dimension. — One of this dimension's main actionable groups (26 issue-level, 0 of them charged here).
Detailed fixes: d29_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether any dependency has a known published vulnerability (CVE), direct or transitive, in ANY ecosystem the repository declares — Dart pub, Elixir and Erlang via Hex, Go modules, Java and Kotlin via Maven/Gradle, JavaScript/npm, .NET/NuGet, PHP/Composer, Python/PyPI, RubyGems, Rust/Cargo and Swift.
Method: Dependency-CVE scan across every ecosystem the repository declares, scored ONCE. Three sources are unioned and deduplicated by advisory identity (rule id + alias closure, CVE<->GHSA) scoped to package+version, keeping the worst severity: `osv-scanner --recursive` over osv.dev for Dart pub, Elixir/Hex (and Erlang, whose `rebar.lock` syft first converts to a CycloneDX SBOM the scanner reads, with rows attributed back to the lock), Go, Java and Kotlin via Maven/Gradle (and Scala, whose sbt build's pinned direct declarations are written into a CycloneDX SBOM the scanner reads, with rows attributed back to the build file), npm, PHP/Composer, Python/PyPI, RubyGems, Rust/Cargo and Swift; `trivy fs --scanners vuln` for npm lockfiles; and `dotnet list package --vulnerable --include-transitive` for NuGet (with per-advisory collapse of the project x target-framework fan-out), plus a DECLARED-dependency arm that resolves a published gem's gemspec against rubygems.org where no Gemfile.lock is committed. `SeverityScore(c,h,m,l, normalizer 8.0)`. NotApplicable only when NO ecosystem is readable; if any applicable ecosystem could not be scanned the findings are REPORTED and the score is withheld. Supersedes the npm and OSV arms, retired 2026-09-05. Advisory since rubric-2026.11.2 (CAI decision 0006): every row is a match against a vulnerability database that changes daily, so the reading is shown and never moves a scored dimension, lens or the headline.
Resolve the 31 Medium IaC finding(s) in IaC & Container Security — start with REDACTED (14), REDACTED (9), REDACTED (6). — One of this dimension's main actionable groups (31 warning-level).
Resolve the 20 High IaC finding(s) in IaC & Container Security — start with REDACTED (6), REDACTED (4), REDACTED (4). — One of this dimension's main actionable groups (20 issue-level).
Resolve the 5 Low IaC finding(s) in IaC & Container Security — start with REDACTED (4), REDACTED. — One of this dimension's main actionable groups (5 recommendation-level).
Detailed fixes: d31_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether anyone still has living knowledge of each file, or it has been orphaned — last understood long ago by someone now gone quiet. The sibling of the bus factor: D16 asks who owns it, D34 asks whether anyone still knows it.
Method: File orphaning as total living-knowledge decay below one focused-commit's worth within a year, computed per-file from the D16 decay model. Exhaustive, deterministic over fixed history.
16 of 170 significant source file(s) are orphaned — their living knowledge has decayed to nothing, so no one currently understands them. The largest is src/llamafactory/train/megatron_bridge/config_builder.py. Counted over 170 of the 242 production source files in this repository: the rest are under the ~2,400-byte size floor this dimension measures over.
Resolve the 1 Orphaned knowledge finding(s) in Knowledge Freshness — start with config_builder.py. — One of this dimension's main actionable groups (1 issue-level).
Resolve the 15 Orphaned file finding(s) in Knowledge Freshness — start with workflow.py (2), triton_grouped_gemm.py, muon_optimizer.py. — One of this dimension's main actionable groups (15 recommendation-level).
Resolve the 1 Further orphaned files (smaller) finding(s) in Knowledge Freshness. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d34_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether files that change together actually belong together — pairs that repeatedly co-change in git history despite having no explicit code dependency, surfacing the hidden/logical coupling (and boundaries in the wrong place) a static scan can't see.
Method: Pairwise co-occurrence over the per-commit file sets in git history (production source only — tests and generated dropped): Degree-of-Coupling = shared ÷ min individual revisions, reported above noise floors (each file ≥10 revisions, ≥5 shared commits, ≥50% strength); sweeping commits excluded. Deterministic over fixed history.
Coverage: Population: PRODUCTION source files only — test and generated files are dropped before pairing, so a class co-changing with its own test (trivially ~100%) can't drown the real production↔production coupling. Pairs ranked by Degree-of-Coupling. A non-source file is never a coupling PARTICIPANT either: documentation, schemas, config and data files are dropped with the rest, so a code↔docs pair — a command and the reference page that restates it — is not reported however strongly the two co-change; nor is coupling that runs THROUGH a build step or config file.
Resolve the 8 Change coupling finding(s) in Change Coupling — start with workflow.py (3), top.py (2), chatter.py. — One of this dimension's main actionable groups (8 warning-level).
Resolve the 3 Change-coupling hub finding(s) in Change Coupling — start with workflow.py (2), train.py. — One of this dimension's main actionable groups (3 warning-level).
Resolve the 1 Change coupling clique finding(s) in Change Coupling — start with cal_lr.py. — One of this dimension's main actionable groups (1 warning-level).
Detailed fixes: d35_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether the build pipeline provides supply-chain integrity — generated provenance/attestation, signed artifacts (cosign/sigstore), an SBOM, and pinned build actions. Presence of the configuration, not a runtime guarantee.
Method: Supply-chain provenance/signing read deterministically from CI/build config (.github/workflows, .gitlab-ci.yml, azure-pipelines, Jenkinsfile, .circleci) + the release surface: four signals — generated provenance/attestation (SLSA/in-toto/actions-attest), artifact signing (cosign/sigstore/gitsign), an SBOM (syft/sbom-action/*.spdx.json/*.cdx.json), and SHA-pinned build actions — scored 10·present/denom. NotApplicable without a build pipeline. Detects configuration presence, not runtime enforcement.
Resolve the 5 REDACTED finding(s) in Supply-chain Provenance & Signing — start with REDACTED, REDACTED, REDACTED. — One of this dimension's main actionable groups (5 warning-level).
Resolve the 1 REDACTED finding(s) in Supply-chain Provenance & Signing. — One of this dimension's main actionable groups (1 warning-level).
Resolve the 1 REDACTED finding(s) in Supply-chain Provenance & Signing. — One of this dimension's main actionable groups (1 recommendation-level).
Detailed fixes: d36_recommendation.md · top locations in Appendix A, every location in findings.md.
What it measures: Whether the repository publishes a coordinated-vulnerability-disclosure policy (SECURITY.md or security.txt) with a reporting contact, so finders know how to report a vulnerability. Presence of a policy file with a contact, not whether the policy is adequate or honoured.
Method: Vulnerability-disclosure policy read deterministically from the repo: a SECURITY.md (root/.github/docs) or .well-known/security.txt / security.txt, regex-checked for a reporting contact (email / URL / mailto). Present + contact → 10; present without a contact → 4; NotApplicable when no policy file exists (it may live off-repo). Detects the policy file's presence + contact, not its adequacy.
What it measures: Whether any dependency the repository declares is published as MALICIOUS rather than merely vulnerable — a package that is an attacker's work, in any ecosystem osv-scanner reads. Reported apart from D30 because the answer is binary: there is no safe version to upgrade to, and the fix is to remove the package and rotate every credential it could have read.
Method: The same dependency scan D30 reads, partitioned on the scanner's own classification rather than rescanned: a row is MALICIOUS when its id is in the `MAL-` space (the ossf/malicious-packages feed) OR its `database_specific.cwe_ids` carries `CWE-506` ("Embedded Malicious Code"). Both channels are structural; the summary text is deliberately NOT read, because a malicious-package record whose summary says only "Critical severity vulnerability" is a real shape ([GHSA redacted]) and a text matcher misses it. Scored BINARY: any surviving row is 0, whatever its severity and however many CVEs sit beside it — a hostile dependency is not a quantity. Applicability and degradation are D30's: NotApplicable only when no ecosystem is readable, and an unscannable ecosystem degrades rather than reading clean. Advisory since rubric-2026.11.2 (CAI decision 0006): the malicious-package feed is a database that changes daily, so the reading is shown and never moves a scored dimension, lens or the headline.
What it measures: Whether anyone still ships security patches for the platform this repository RUNS ON — the runtime it pins and the framework majors its own constraints hold it to. Separate from D12 because the question differs: a current Django on an end-of-life Python is perfectly up to date and completely unsupported, and the fix is a migration rather than a version bump. What the repository says it merely SUPPORTS is never charged.
Method: End-of-life PLATFORM read from the repository's own declarations and graded against a FROZEN, dated table of vendor support dates — no network, no feed, no API, so this dimension answers identically inside a closed scan fence. Two subjects: a RUNTIME the project pins (a single or all-end-of-life TargetFramework, a .nvmrc or .python-version, a requires-python CAP) and a FRAMEWORK major a dependency constraint cannot move off (a caret, tilde or exact version; `vue@^2.7.16` pins Vue 2). A FLOOR is deliberately never charged — `requires-python = ">=3.8"` states what a package SUPPORTS, not what it runs on — and a multi-target project is charged only when EVERY target is out of support. Runtime 4.0/product capped 8.0, framework 1.5 capped 4.5. The table is safe to freeze because a statement about support that ended in the past cannot become false: it loses recall as it ages, never precision, and a test asserts every entry predates the freeze date. Disjoint from D31 (a container image's OS layer) and D29 (the toolchain a CI workflow installs). Abstains when the repository declares no platform this pass reads — never scores it clean.
0 end-of-life runtime(s) and 0 end-of-life framework(s), read from 1 platform declaration(s) and 31 dependency declaration(s). This dimension reads what the repository says about ITSELF — a pinned target framework, a version file, a capped requires-python, a Rust toolchain pin, a framework major a constraint cannot move off. A FLOOR is deliberately never charged: `requires-python = ">=3.8"` states what the package SUPPORTS, not what it runs on, and a well-maintained library declares exactly that while running its own CI on a current release. The end-of-life facts are FROZEN and dated, so this dimension needs no network and answers identically inside a closed scan fence; as the table ages it loses recall and never precision, because a statement about support that ended in the past cannot become false. The OS layer of a container image is D31's question and the toolchain a CI workflow installs is D29's; this row is neither.
Other · Architecture — How the codebase splits by code ROLE — domain, application, infrastructure, test, generated. The significance map behind the knowledge/coupling weighting, and a DDD signal in its own right: a thin domain core under fat infrastructure is the anemic-domain smell, quantified. How each file's role is decided, because the split is only as good as that: a generated name or a build-output tree makes it Generated, a test project makes it Test, and otherwise the file's NAMESPACE and PATH words are matched against fixed vocabularies in a fixed ORDER — domain, then infrastructure, then application — so a file whose words hit two layers is counted under the earlier one. A production file matching none of them counts as application, so that share reads 'application or unclassified' rather than a measured application layer. Roles come from naming convention, never from what the code does. On this repository the split was taken from the source tree on disk rather than from a loaded .NET workspace, so a file's role is decided by its PATH segments alone — no declared namespace was available to add to the evidence — and generated output is excluded from the census entirely rather than counted as a generated share.
Method: Roslyn line-count by code ROLE: every source file classified Domain/Application/Infrastructure/Test/Generated by namespace + path convention (the shared CodeRoleClassifier), then significant lines summed per role. Deterministic; the advisory score is the business-logic (domain+application) share of production code.
Coverage: Population: ALL source files, each bucketed into ONE of five roles (Domain/Application/Infrastructure/Test/Generated) by namespace + path convention — a file whose layer isn't named in the convention falls to Application (the neutral default), and the split is line-count, not semantic depth or business value.
Other · Architecture — Whether the project-reference graph is acyclic (cycles block independent build/deploy and signal eroding boundaries).
Method: Project reference cycles via elementary-DFS over real .csproj references, using the engine shared with D5/D7; cyclic versus acyclic. Exhaustive, deterministic.
Other · Architecture — Whether dependencies point inward (Domain ← Application ← Infrastructure/Web) — the clean-architecture dependency rule, checked across the project graph.
Method: Layer violations by name-segment inference (Domain/Core to Application to Infrastructure/Web) over the project-reference graph. Exhaustive over all projects, deterministic.
Do you agree with this assessment?
C2 · Access Controls7.0 / 10Strong✓ Tool-verified
Other · Security — Whether access is authorized by default — a framework authorization attribute/decorator or policy, or imperative guard methods (throw-on-violation) called from handlers.
Method: Roslyn scan: [Authorize] usage and authorization policies, plus imperative throw-on-violation guard methods detected via syntax. Deterministic.
Authorization IS enforced here (by route guards, auth middleware or checks that refuse a caller) — this is NOT a claim that endpoints are unprotected. What's missing is a NAMED rule set: who may do what is encoded inline where it is checked, so the rules can't be listed, reviewed or tested apart from the code that applies them. Recommendation, not a defect.
What to do
Name the access rules — DRF permission classes, django-guardian or django-rules permissions, a casbin or oso policy, or roles and permissions declared once — and consult them where access is checked (permission_classes, @permission_required, Depends), so the rule set is reviewable and testable on its own.
Maturity · Maturity — Whether the repository and its projects have a README, and whether it is substantive.
Method: Filesystem scan: README presence, word count, and headings for depth; git history for staleness. Exhaustive across root and project dirs, deterministic.
What to do
Explain in the README how to run the tests. Add a section called Testing to the README in the repository's top folder, saying how to run the test suite.
Maturity · Maturity — Whether key decisions (ADRs) and the high-level shape (C4/diagrams) are written down.
Method: Filesystem scan: ADR folder/naming conventions or content, plus Mermaid/PlantUML/C4/architecture.md discovery. Exhaustive, deterministic.
No Architecture Decision Records found — no conventional ADR directory, no numbered `NNNN-title` documents in any markup this check reads, and nothing ADR-shaped by content. Design rationale recorded elsewhere (a design-notes tree, a mailing list, pull-request discussion) is not visible to this check and is not re-findable per decision, so a future maintainer cannot ask why one choice was made and get an answer.
What to do
Record your significant design decisions. Write one short document per decision, giving its date, the situation, the decision and its consequences, and keep them together with your other design documents. A docs/adr folder with each file named by number and title is the easiest place to find them.
Maturity · Maturity — Whether the repository is organised deliberately: production code and tests are set apart in a way its ecosystem or the repository itself declares.
Method: Filesystem scan: src/test folder separation and namespace-prefix consistency (majority RootNamespace agreement). Exhaustive across projects, deterministic.
Maturity · Maturity — Whether the project's current-state documentation describes the code that exists.
Method: Every current-state document's checkable claims looked up in the tree (links, versions, and artefact counts an order of magnitude off), plus two README checks: an advertised infrastructure product with no footprint, and a module the CHANGELOG records as removed. Deterministic, no model. Advisory.
Readiness · Readiness — Whether an automated pipeline builds and tests every change.
Method: Filesystem scan: CI workflow files (.github/workflows, .gitlab-ci.yml, etc.) for build and test stages. Exhaustive, deterministic.
Do you agree with this assessment?
P10 · Library API & versioning10.0 / 10Exemplary○ Nothing flagged
Readiness · Readiness — For a library: a deliberate (small) public API surface and explicit semantic versioning so consumers can depend on it safely.
Method: Roslyn scan: public API surface area and semantic-versioning markers (SemVer attributes, changelog entries) for libraries; off .NET, a library is the ecosystem's publication act (an npm package that is not private and names an entry point, a PyPI distribution with a build system, a Rust library crate, a Maven/Gradle module that publishes, a Go module with no package main, a gemspec, a Composer library, a SwiftPM library product, a pub.dev or Hex package), its surface is the share of types the language's code model records as public (Rust, Swift, Java, Kotlin, Go, Dart; not measured where the model records no type visibility or, as in TypeScript, only module-level export), and its version is read from the manifest, a semver CHANGELOG, release tooling or semver git tags. Exhaustive, deterministic.
Do you agree with this assessment?
P2 · Observability7.0 / 10Strong✓ Tool-verified
Readiness · Readiness — Whether the code is diagnosable in production — structured logging, tracing/metrics, health checks.
Readiness · Readiness — Whether SAST, secret/dependency scanning and performance benchmarking are wired in (presence, not runtime).
Method: Filesystem scan: SAST configuration, dependency-update automation, secret scanning, and a benchmark harness or benchmark step — in this repository's own ecosystem. Exhaustive, deterministic.
No static application security testing detected. For this repository's stack, add bandit, `semgrep --config=p/python`, or CodeQL's python pack as a CI step. What was searched, so you can tell an absence from a miss: the 8 CI workflow file(s) in this repository, and the scanner and linter configuration checked in beside them. A scan that runs outside CI, one configured in your forge's web UI rather than in a committed file, or a tool whose name is none of those this check carries, is not seen — if that is your case the row is wrong, and saying so is more useful than adding a second scanner. — REDACTED:13
What to do
Add a SAST step to CI running what this repository's stack ships: bandit, `semgrep --config=p/python`, or CodeQL's python pack — so a security regression fails the build instead of landing.
Enable Dependabot/Renovate or a dependency-review gate.
Add gitleaks/trufflehog in CI to block PRs that introduce committed secrets.
Readiness · Readiness — Whether releases are automated and safely reversible (probes, rolling updates, approval gates) — from manifests/pipeline files, not the live environment.
Method: Filesystem scan: deployment manifests/IaC (K8s YAML, Helm, Terraform) for rolling updates, probes, approval gates, migration hooks. Exhaustive, deterministic.
Deployment is orchestrated by compose, but no service declares a `healthcheck:` and nothing pins a previous image to fall back to — the runtime can tell that the container is up, not that it is serving, so a bad release is harder to detect and reverse.
What to do
Add a `healthcheck:` to the served compose service — probing the endpoint it already answers on where it has one — with `depends_on: condition: service_healthy` on whatever waits for it, and keep the deployed image tag immutable and recorded so rolling back is re-pointing at the previous tag rather than rebuilding.
Readiness · Readiness — Whether releases are traceable — a maintained changelog and explicit version stamping.
Method: Filesystem scan: changelog file presence and version tags in csproj or git tags. Exhaustive, deterministic.
No CHANGELOG/HISTORY/RELEASES file — what shipped when isn't easy to reconstruct for support or audit. (Versioning/tagging makes releases traceable, but a changelog records the what.)
What to do
Keep a changelog (e.g. Keep-a-Changelog) recording what shipped in each release.
Readiness · Readiness — Whether outbound HTTP calls are wrapped in resilience (retry/timeout/circuit-breaker) so a failing dependency doesn't cascade.
Method: Source scan: outbound HTTP clients and what bounds them — resilience handlers (Polly, AddStandardResilienceHandler) on .NET; on Go, the JVM, Python, JavaScript/TypeScript, Ruby, PHP, Rust, Elixir, Swift, Dart and Erlang, a timeout, deadline, retry or breaker beside each call, or a process-wide client default (a framework-wide deadline such as Drupal core's, Laravel's or actix's awc counts). Exhaustive, deterministic.
`requests.get(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout. (×3) — src/llamafactory/api/chat.py:131, src/llamafactory/api/chat.py:144, src/llamafactory/api/chat.py:157
`requests.post(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout. (×2) — src/llamafactory/chat/sglang_engine.py:220, src/llamafactory/train/ppo/ppo_utils.py:38
What to do
Pass `timeout=` on every `requests`/`httpx` call (requests has no default and will wait forever), mount an `HTTPAdapter(max_retries=Retry(...))` on shared sessions, and wrap calls to flaky dependencies in `tenacity` retries or a `pybreaker` circuit breaker.
Readiness · Performance — Whether asynchronous code stays responsive — it avoids sync-over-async blocking (a .NET .Wait()/.GetAwaiter().GetResult(), a time.sleep or blocking HTTP call inside a Python coroutine, a *Sync call inside an async JavaScript function, block_on inside a Rust async fn, runBlocking inside a Kotlin suspend function, block() inside a Reactor publisher) that stalls a thread or event loop and risks deadlock, and, where the code is a reusable library on .NET, awaits with ConfigureAwait(false) so it never captures and stalls its caller's context.
Method: Production-source scan: sync-over-async blocking counted everywhere — .Wait()/.GetAwaiter().GetResult() in .NET; off .NET, read from each language's code model, a blocking call inside an async function (Python, TS/JS, Rust, Kotlin, Swift, Dart) or inside a Java method returning a Reactor Mono/Flux or a Scala method returning a Future or effect — and, for a .NET library with ≥5 awaits, the share of awaits using ConfigureAwait(false). Deterministic, syntax/text detection.
Other · Code Health — Whether the code avoids sync-over-async (deadlock-prone blocking on tasks) and async void.
Method: Roslyn syntax scan: async methods scanned for .Wait()/.GetAwaiter().GetResult() and async-void outside event handlers. Deterministic, hard fact per invocation.
The task this creates is not kept anywhere. The event loop holds only a weak reference to its tasks, so a task nobody references can be garbage-collected before it finishes (Python's documentation for `asyncio.create_task`: save a reference to the result); and nothing ever awaits it, so an exception it raises is never handled — it surfaces, if at all, as "Task exception was never retrieved" in a log. Keep the task: `await` it, gather it, start it in an `asyncio.TaskGroup` (`async with asyncio.TaskGroup() as tg: tg.create_task(…)`), or, for genuine fire-and-forget, add it to a set and `task.add_done_callback(tasks.discard)` with a callback that also reads its exception. — REDACTED:63
Other · Code Health — Whether any branch is dead by construction — a switch arm whose label can never equal a case-normalised subject, or an `else if` whose predicate the arm above has already swallowed.
Method: Roslyn syntax + semantics: switch labels compared against the subject's own case normaliser, and if/else-if chains checked for a literal an earlier arm's containment test already swallows. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X13 · Undrained process stream10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a child process that has BOTH standard streams redirected drains both — reading one to the end while the other is never read deadlocks once the child fills the unread pipe.
Method: Roslyn syntax + semantics: ProcessStartInfo launches with both streams redirected, checked for a drain of each stream across the enclosing type. On a repository with no .NET source it reads JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not) with the same rule: a `spawn` imported from `child_process` whose stdout and stderr are both pipes (no options, no `stdio`, or `stdio` of `'pipe'`), bound to a local that never leaves its scope, where exactly one of the two streams is read, the other never, and the child’s `close`/`exit` (or the read stream’s end) is awaited; a shell redirect in the call’s arguments or a `kill` of the child suppresses it. The same rule reads Python’s `subprocess.Popen`, Dart’s `Process.start`, Ruby’s `Open3.popen3`, and Scala’s JDK process starts (`new ProcessBuilder(…).start()` with no `redirectErrorStream`/`redirectError`/`redirectOutput`/`inheritIO`, `Runtime.getRuntime.exec`) where one of `getInputStream`/`getErrorStream` is read and the other never while `waitFor()` is called or the read stream is read to its end. Deterministic, provable per finding. Advisory.
Other · Code Health — Whether a method that temporarily changes state belonging to the whole process — the working directory, an environment variable — puts it back on EVERY path: a restore reached only when nothing throws leaks the change to the rest of the process.
Method: Roslyn syntax + semantics: method bodies that write the process working directory or an environment variable and write it back in the same body, checked for whether that restore sits in a `finally`/`catch` or only on the straight-line path. On a repository with no .NET source the same rule reads production JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not): `process.chdir`, `process.env.NAME =`/`["NAME"] =` and `delete process.env.NAME`, and Deno’s `Deno.chdir`/`Deno.env.set`/`Deno.env.delete`, paired per function body (a nested function or arrow is its own body, and module top-level code is none), where the last write puts back a local the body captured from the same global or deletes a variable the first write set, with at least one statement between them; a write in a `catch`/`finally` of that body silences it. Deterministic, provable per finding. Advisory.
Other · Code Health — Whether the work a diagnostic log line costs is paid only when that line is wanted — C# evaluates a call's arguments BEFORE the call, so a trace/debug message joined or projected out of a collection is built in full on every pass, and then discarded by a sink the shipped configuration leaves switched off.
Method: Roslyn syntax: log calls at a diagnostic level (a `Log`-prefixed method naming Trace/Debug/Verbose, or a bare `Debug`/`Trace`/`Verbose` on a receiver named for a logger), whose argument list is read for a call whose cost scales with a sequence — a LINQ operator, a materialisation, `string.Join`, a serializer — with no enclosing level check or conditional-compilation region. On a repository with no .NET source it reads JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not) with the same rule: a `debug`/`trace`/`verbose` call on a receiver named for a logger, or a `log`-prefixed method naming the level, whose argument calls an array operator (`map`/`filter`/`reduce`/`sort`/…), `Array.from`, `Object.keys/values/entries`, `JSON.stringify`/`util.inspect` over anything but a literal, or an array `join` — outside any arrow or function passed as an argument, which the logger calls only when the level is on — with no enclosing `if`, `&&` or `?:` whose condition names a level, a level string, or the `NODE_ENV`/`__DEV__`/`DEV` build switch. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X24 · Document value interpolated into markup unescaped10.0 / 10Exemplary○ Nothing flagged
Other · Security — Whether text read out of the document being converted is escaped before it is written into generated markup — a value the document's author chose, interpolated into an attribute the surrounding literal delimits, can close that attribute and open another.
Method: Roslyn semantic model over the whole compilation: a string-typed `Value`/`InnerText`/`InnerXml`/`Text` member declared inside `DocumentFormat.OpenXml` or `System.Xml` is a taint SOURCE, propagated through assignments, returns, arguments, tuple elements and string composition to its transitive closure, then read at interpolated-string holes that sit in a markup position the surrounding literal itself delimits. Escaper/encoder calls and enclosing validator conditions cut the flow. Flow- and container-insensitive by construction. A second arm needs no provenance at all and reports a type that CONTRADICTS ITSELF — the same expression escaped at one delimited markup hole and interpolated raw at another hole in the same markup position of the same type, which the type's own escaping proves is a defect without knowing where the value came from. On a repository with no .NET source it reads JavaScript/TypeScript off the token stream with the same rule: a DOM read of raw document text (`getAttribute`, `textContent`, `innerText`, `nodeValue`) is the source, propagated through local bindings and string composition, and judged at template-literal and concatenation holes in the same two delimited markup positions; escapers and validating conditions cut it, and documentation-site, test, vendored and minified scripts are not read. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X27 · Collection changed while being enumerated10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a `for` loop leaves the `dict`, `set` or `deque` it is walking alone — CPython's iterators over those check that the collection has not changed size since the loop began, so a body that removes from (or empties) the very collection the loop is walking makes the next step raise `RuntimeError: dictionary changed size during iteration` and the remaining items are never seen.
Method: Roslyn syntax + semantics: `foreach` statements whose body calls a structural mutator (`Add`/`Remove`/`Clear`/`Insert`/…) on the very expression the loop is enumerating. Two arms. ARM A — the source is a concrete fragile BCL collection, or a live `Keys`/`Values` view over one, and the mutator resolves to that same collection's own member; concurrent and immutable collections and arrays are outside the population by construction, since their enumerators survive a structural change. ARM B — the source is an argument-less accessor CALL on a receiver whose body is in source: the accessor must return a stored field VERBATIM and a sibling member must structurally change that same field, both read off the implementations rather than from the members' names. A mutation the loop provably exits immediately after (`break`/`return`/`throw`/`goto`), or one written inside a nested loop or a lambda, is counted and never reported. Deterministic, provable per finding. Advisory.
Do you agree with this assessment?
X28 · Index access outside its own emptiness guard10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a condition that tests a value for emptiness indexes that same value only where the test holds — an `||` written one parenthesis too far to the left leaves an index access outside the guard beside it, so the empty case the guard exists to anticipate reaches the index and throws.
Method: Roslyn syntax only, no semantic model: the OUTERMOST `&&`/`||` of every boolean condition, read for a symbol the condition tests for emptiness (`string.IsNullOrEmpty`/`IsNullOrWhiteSpace`, a `Length`/`Count` comparison against a literal, `Any()`, a `Length`/`Count` pattern, or a comparison against `""`) and ALSO indexes. Each `symbol[...]` access is placed by a boolean-reachability walk from the access up to the outermost connective: an access is COVERED when some enclosing step has it in the right operand and the left operand, under the truth value that step forces, proves the symbol non-empty — a recursion over `&&`/`||` whose true- and false-directions are asymmetric. A finding needs BOTH an uncovered access and a covered one on the same symbol in the same condition, which is the agreeing twin that separates a misplaced parenthesis from an unrelated length test. Bare index accesses with no emptiness test in the condition are neither counted nor reported; a non-identifier receiver and a lambda nested inside the condition are outside the population. Deterministic, provable per finding. Advisory.
Other · Code Health — Whether exceptions are handled rather than silently swallowed or rethrown with lost stack traces.
Method: Roslyn syntax scan: every catch clause counted; empty catches and bare rethrows flagged. Population is all catch clauses, not estimated. Deterministic, hard fact.
An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it. (×8) — src/llamafactory/webui/common.py:55, src/llamafactory/train/callbacks.py:401, src/llamafactory/extras/env.py:57, …
`except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter. (×10) — src/llamafactory/webui/common.py:79, src/llamafactory/webui/common.py:159, src/llamafactory/v1/plugins/model_plugins/kernels/ops/rms_norm/supa_rms_norm.py:66, …
An empty catch block silently discards the error — failures vanish with no log and no rethrow. On a teardown path letting it propagate is not an option (throwing out of `__del__()` masks the failure already in flight and abandons the rest of the cleanup), so make the swallow deliberate instead: narrow the catch to the exception this release can actually raise, and record it through whatever this codebase already uses to report problems — or, if it truly cannot matter, say why in a comment on the catch. — src/llamafactory/chat/sglang_engine.py:291
What to do
Swallowed exception (empty catch)
Do you agree with this assessment?
X30 · Support guard that admits what it rejects10.0 / 10Exemplary○ Nothing flagged
Other · Code Health — Whether a guard written as a NEGATED `||` says what its author meant — `!(a || b || x != k)` is `!a && !b && x == k` by De Morgan, so a bail-out that mixes capabilities the code needs with a fault it refuses turns inside out: it fires only where the capabilities are ABSENT, and lets every value the fault term names walk straight into the body that cannot handle it.
Method: Roslyn syntax only, no semantic model: every logical-not whose operand is a parenthesised `||` chain of two or more disjuncts, flattened (a left-nested `a || b || c` read once would see `(a || b)` as one disjunct). A site enters the population on that shape alone. A finding additionally needs the disjuncts to DISAGREE in polarity: at least one bare boolean read — an identifier or member access, never an invocation, which is a predicate rather than a capability flag — and at least one `x != <constant>`, the only form that negates into an exact-value pin (`== null` negates into a looser requirement and is outside the fault set). Consistently-polarised disjunctions, all-fault or all-capability, are counted and never reported; a negated `&&` is outside the population entirely. No same-receiver gate: it was measured to cost a real defect and remove no false positive. Deterministic, provable per finding. Advisory.
Other · Code Health — Whether log calls use message templates (queryable) rather than interpolated strings.
Method: Roslyn syntax scan: every log call-site counted; interpolated-string first-argument violations flagged. Population is all log calls, not estimated. On a repository with no .NET source it reads JavaScript/TypeScript off the engine’s own token stream (test, vendored and minified paths not) with the same rule: a `trace`/`debug`/`info`/`warn`/`error`/`fatal`/`verbose`/`silly`/`http`/`log` call on a receiver named for a logger, in a package whose own or an enclosing `package.json` declares a logger that carries values as fields (pino, pino-http, nestjs-pino, Fastify, winston, bunyan, tslog, LogTape, roarr), whose first deciding argument is a template literal with substitutions; an object-literal fields argument is stepped over, a plain string message clears the call. Python is read the same way: a `debug`/`info`/`warning`/`error`/`exception`/`critical`/`log` call on a logger in a file that imports the standard library’s `logging` or structlog (loguru, which formats at the call, is not judged), whose message is a whole f-string with a non-constant field; a `%`-formatted, `.format()`-ed or concatenated message is not convicted, as in C#. PHP is read the same way: a PSR-3 level call (`emergency`…`debug`, `log`) on a logger (`$logger`, `$this->logger`, Laravel’s `Log::`, `logger()`, `\Drupal::logger()`) in a package whose `composer.json` requires a PSR-3 logger or a framework that hands one out (psr/log, Monolog, Laravel, Symfony, Drupal, CakePHP), or a file that imports one, whose message is a double-quoted string interpolating a variable; a single-quoted message clears the call, and `sprintf` or `.` concatenation is not convicted, as in C#. Dart is read the same way: a `trace`/`debug`/`info`/`warn`/`error`/`fatal` call on Sentry’s structured logger (`Sentry.logger`) whose message is a whole string literal interpolating a value (`$name`, `${…}`); the `Sentry.logger.fmt` template API clears the call. Dart that logs only through loggers with one message and no fields (package:logging, package:logger, talker, dart:developer) is not applicable rather than a reach gap. Ruby is read the same way: a `trace`/`debug`/`info`/`warn`/`error`/`fatal` call on the console gem’s `Console` (declared by a Gemfile, gemspec or Gemfile.lock, or required) or, where SemanticLogger, Ougai or dry-logger is declared or required, on a receiver named for a logger (`logger`, `@logger`, `Rails.logger`, `log`), whose first deciding argument is, as the whole argument, a double-quoted string interpolating a non-constant value (`#{…}`, `#@ivar`); a plain literal clears the call, keyword arguments are the fields, and a block, `%`-format or `+` concatenation is not convicted. Ruby that logs only through the standard Logger (Rails.logger) is not applicable rather than a reach gap. Deterministic.
`info` at line 303 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:303
`info` at line 394 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:394
`info` at line 421 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog. — src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:421
The score is the rank-weighted fold of these lenses (worst-heaviest), each including its meta-dimensions; a lens with a Critical contributor is capped at Fair (its band reads "gated by …") and is never the strongest area however high its average.
Unscored — 2 check(s) recorded observations but carry no score
These checks ran and found something, but they do not carry a score — either by design (an advisory check reports evidence rather than grading it) or because they could not be scored here. They are excluded from the score for that reason, not because there was nothing to see.
X10 Duplicated predicate — 24 observation(s) recorded · Advisory — this card reports evidence and never carries a score.
X7 Silent fallback defaults — 2 observation(s) recorded · Advisory — this card reports evidence and never carries a score.
Not evidenced — 1 control(s) we could not find positive evidence for
These checks grade a working control, and the repository shows no evidence of one. That is deliberately not scored as a zero: a repository cannot show an ops runbook, a database TTL or an infrastructure-side audit log, so absence of evidence here is not evidence the control is missing. It is also not a statement that the check is irrelevant to this codebase — the thing it grades applies; we just could not see it. Excluded from the score either way.
P5 DR & Backup — not evidenced — repo shows no backup/RTO/RPO controls; absence of evidence is not evidence of a working control
Not included — 63 check(s) not relevant to this codebase
These checks had nothing to measure here (no tests, no git history, the codebase is small, or the architecture style doesn't apply), so they're omitted above rather than scored low.
AC1 Text alternatives — No web markup found — accessibility is not applicable to this repository.
AC2 Forms & labels — No web markup found — accessibility is not applicable to this repository.
AC3 Page structure — No web markup found — accessibility is not applicable to this repository.
AC4 Keyboard semantics — No web markup found — accessibility is not applicable to this repository.
AC5 ARIA correctness — No web markup found — accessibility is not applicable to this repository.
AC6 Visual & motion safety — No web markup found — accessibility is not applicable to this repository.
AX1 Captive dependencies — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX2 Stateful singletons — No container singleton was found, so there is no shared instance for concurrent requests to race on. No function in this Python code is served by a threaded web framework (a Flask, Bottle or FastAPI route, a Django or Pyramid view), so no module is shared between request threads. TypeScript/JavaScript runs each process's requests on one event loop, so no two requests write a shared object at the same instant (interleaving across an await is a different defect).
AX5 Architecture & structure — not assessed — architecture style/structure is computed from a project graph (projects, types, module namespaces) that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX6 Interface segregation — not assessed — interface segregation is computed over a type surface that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
AX7 Slice cohesion — not applicable — not a vertical-slice architecture
AX8 Test isolation — no test/production split to check
AX9 CQS / query purity — no CQRS query handlers detected — query purity is not applicable to this codebase
AXB2 Runtime readiness — Advisory — this card reports evidence and never carries a score, so there is nothing missing here.
AXR1 Runtime accessibility — compose up failed (exit 17 — an image could not be built) — llamafactory Pulling llamafactory Warning pull access denied for llamafactory, repository does not exist or may require 'docker login': denied: requested access to the resource is denied failed to solve: failed to register layer: write /opt/intel/oneapi/debugger/2026.1/opt/debugger/src/dependencies.tar.gz: no space left on device; runtime evidence skipped This is a statement about this run, not a statement about your application: nothing here says the surface is inaccessible, only that it was never rendered.
C1 Data Protection — Not assessed: these personal data controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks personal data controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
C3 Audit Trail — No personal data detected in a persisted data model — no PII-named field (email, first_name, date_of_birth, phone, …) or stored credential in a Django, SQLAlchemy, SQLModel, Peewee, Tortoise or MongoEngine model, a migration or a SQL schema — and no database or data-store client (Django ORM, SQLAlchemy, psycopg, PyMongo, …) in the source either, so this repository keeps no sensitive data whose changes an audit trail would record. If it does (through a store configured outside this repository, for instance), the trail belongs to wherever that data is stored.
C4 Data Retention — No personal data detected in a persisted data model — no PII-named field (email, first_name, date_of_birth, phone, …) or stored credential on a Django, SQLAlchemy, SQLModel, Peewee, Tortoise or mongoengine model, in a migration or in a SQL schema — and no database or data-store client (django.db, sqlalchemy, psycopg2, pymongo, sqlite3, …) imported either, so this repository keeps no personal data whose lifetime a retention limit would bound.
C5 Data-Subject Rights — No personal data detected in a persisted data model — no PII-named field (email, first_name, date_of_birth, phone, …) or stored credential on a Django, SQLAlchemy, SQLModel, Peewee, Tortoise or mongoengine model, in a migration or in a SQL schema — and no database or data-store client (django.db, sqlalchemy, psycopg2, pymongo, sqlite3, …) imported either, so this repository keeps no personal data for a data subject to erase, export or consent over.
D10 Test Quality — ~7764 lines of test source are present (.py) but no test cases reached the test census for this repository — no test root we could resolve declared them, or the files we read declare no cases in a test framework we recognise — so skipped/assertion-free tests couldn't be counted. Not scored — this is a gap in the analyzer, not a finding about this repository.
D11 Test Reliability — Test reliability not included — the .py suite was found but not re-run
D12 Dependency Hygiene — Dependency currency not established — no declaration carries an exact pin to grade
D18 Solution Shape — D18 scores the shape of a .NET solution; this repository has no .NET solution or project files, so the dimension does not apply.
D21 Naming Consistency — D21 withholds its case and prefix conventions rows: 1 candidate(s) found and not reported.
D22 Internal API Consistency — API consistency is measured on C# only; the exposed Python surface was not measured.
D23 Boundary Type-Coupling — No bounded-context organisation was detected either — neither a context-shaped layout, nor 2+ sibling source directories each declaring an aggregate root, nor 2+ sibling projects each declaring an entity of their own or taking another project's integration events. Declaring this codebase's bounded contexts (≥2) would let cross-boundary type coupling be assessed. Declare them in `.codehealth/config.yaml` at the repository root (create it if absent), mapping each context name to the module-path or namespace prefixes that belong to it — e.g. `architecture:` → `contexts:` → `Billing: ["src/billing", "Acme.Billing"]`, `Catalog: ["src/catalog", "Acme.Catalog"]`.
D24 Comment Value — D24 reads C#, Visual Basic, TypeScript and JavaScript comments only; comments in this repository's .py source were not judged.
D25 ADR Conformance — no ADRs to check
D32 Data Compliance (PII/GDPR) — No personal data was found crossing a boundary the PII/GDPR ruleset checks — nothing written to a log or console sink, placed in a URL or query string, or persisted to browser storage. That is a clean result for the LEAK surface only: this ruleset detects personal data escaping, it does not inventory the personal data a repository holds, so it is not evidence that this repository has no personal-data surface. The personal-data map (Appendix C) and the C1-C5 compliance cards are what speak to that.
D40 Network Egress Confinement — No Kubernetes/orchestration workloads found in the repository manifests; network egress policy is a cluster-native control that may live at the platform/firewall layer, so there is nothing to assess here.
D41 Kernel & Syscall Confinement — No Kubernetes/orchestration workloads found in the repository manifests; seccomp/AppArmor/SELinux confinement is a workload-level control, so there is nothing to assess here.
D42 Runtime Threat Enforcement — No Kubernetes/orchestration workloads found in the repository manifests; runtime threat-detection and admission-control policy are cluster-level controls, so there is nothing to assess here.
D5 Coupling — Not applicable — this Python build ships 1 production module(s), so there is no coupling BETWEEN modules to measure. (Its test and non-production modules are not part of the shipped graph.)
D7 Architectural Integrity — no checkable ADRs, and no project-reference graph for the cycle pass to read — so this dimension makes no claim about dependency cycles in either direction (where this repository's language has an import-cycle lens, cycles are reported there). Architectural integrity not assessed
D8 Code Coverage — Coverage not included — suite not readable by the collector
DM1 Domain Modelling — not scored — this repository shows only 1 of the 3 signals this lens looks for (92 value object(s))
ED1 Event-Driven — not scored — this repository shows none of the 3 signals this lens looks for
ED5 Idempotency — no mutating command handlers or message consumers detected — idempotency check not applicable
ES1 Event Sourcing — not scored — this repository shows none of the 3 signals this lens looks for
GD1 Unfinished & placeholder code — no source files were read — this check reads C#, F#, JavaScript/TypeScript, Dart, Ruby and Scala, and none was read for this repository's product. That is a limit of the analyzer, not a finding about your code.
IC1 Incompleteness & stubs — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
P12 CI test-gate honesty — Reported, not scored — and nothing was matched here. The coverage check applies to any stack, and the automatic-re-run check to any GitHub-Actions workflow, but the checks for excluded tests, skipped tests and sleep-based synchronisation currently recognise only some ecosystems' test-runner idioms, so on a repository built with another stack the zeros below mean 'not checked', not 'clean'.
P8 Schema migrations — no ORM, schema-migration tool or schema auto-create was found in this repository's dependency manifests or source, so there is no database schema for this check to judge
P9 Domain vs controller coverage — coverage not measured: this check compares the coverage of the analyzer's own test run across the domain and web layers, and that run measured none here — Test coverage (D8) says why
PF1 Benchmark discipline — Not applicable: no benchmark suite was found. This check searched for a pytest-benchmark or pytest-codspeed dependency with tests taking the `benchmark` fixture, an asv.conf.json with its `time_`/`mem_`/`peakmem_` benchmarks, or a pyperf Runner, and for a `*benchmark*` script that this repository's CI runs. Benchmarks are credited as a bonus, so their absence is neither scored nor deducted.
PF2 Allocation hygiene — Not scored: this check counted allocation-aware idioms (Span, pools, stackalloc) per line, which describes what kind of code a repository is rather than whether it has an allocation problem, so it was withdrawn. Nothing here is a finding about your code.
S1 Web-Security Posture — Not assessed: these web-security controls are read from a source model (declarative annotations, request middleware, entity/column names, guard methods) that was not loaded for this repository — because the repository is written in a language this check does not yet model, or because its projects failed to load. Absence of an idiom this check recognises is NOT evidence that this repository lacks web-security controls: it may implement them entirely in its own ecosystem. This is a gap in the analyzer's language coverage, not a finding about this repository.
X14 Bypassable address classification — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X15 Unvalidated length from an untrusted reader — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X16 Unfloored truncation loop — X16 reached only 0% of this repository's production lines — python (45,085 lines) was left unread. Not scored: a score over a minority of the product would be published as the whole of it.
X17 Uncapped recursion over a caller-supplied document — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X18 Disposal-pattern correctness — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X2 Cancellation propagation — no C# was loaded; this repository's Python was read, and no request in it can be cancelled by a caller — a Python request takes no token: asyncio cancels the task and trio or anyio the scope that made it, from outside the call, and requests, httpx, aiohttp and gRPC take a timeout, not a cancellation
X20 Mistyped argument guard — This check asks whether an argument guard reports an EMPTY value as a NULL one, which needs a language that throws a null-specific argument exception — .NET's ArgumentNullException, the JVM's NullPointerException, Dart's ArgumentError.notNull. This repository contains none of those languages: the ones it is written in have a single exception for a bad argument, so there is no pair of exceptions to confuse and nothing here for it to assess. Not a gap in the analyzer and not a finding about your code.
X21 Side-effecting pattern guard — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X22 Contradicted release guard — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X25 Inert configuration knob — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X26 Unsynchronised callback handoff — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X29 Per-element action decided by a fixed element — not applicable — the code was read and holds no site of this kind, so there is nothing for this check to judge
X32 Type resolved by simple name across every loaded assembly — This check is about how a .NET program searches the assemblies loaded into its process for a type, and this repository contains no .NET source, so there is nothing here for it to assess. Not a gap in the analyzer and not a finding about your code.
X5 Nullable reference types — not analysed — these correctness checks read a source model that was not loaded for this repository, because the repository is written in a language this check does not yet model, or because its projects failed to load. This is a gap in the analyzer, not a finding about this repository
X6 Hand-rolled structured-format parsing — Advisory — this card reports evidence and never carries a score, so there is nothing missing here.
X9 Subsumed condition operand — Advisory — this card reports evidence and never carries a score, so there is nothing missing here.
Appendix A — Findings (grouped)
The findings behind the scores, grouped by severity, then by dimension and kind. The high-severity issues are enumerated in full below; items per group are capped at 25 with any overflow stated explicitly per group, never silently truncated. The complete machine-readable list of every finding (all severities) is the companion findings.md in this report's bundle.
Orphaned knowledge src/llamafactory/train/megatron_bridge/config_builder.py:1— No living knowledge remains for this large file — its last meaningful change has decayed away; if it breaks, no one currently understands it. Schedule a read-through / add characterisation tests before it bites.
TodoComment tests/e2e/test_sglang.py:48— # TODO: Change to EXPECTED_RESPONSE — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment src/llamafactory/v1/plugins/model_plugins/peft.py:124— # TODO — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment src/llamafactory/v1/plugins/model_plugins/peft.py:274— # TODO — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment src/llamafactory/v1/plugins/model_plugins/parallelization/ulysses.py:127— # TODO Merge three alltoall calls into one — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment src/llamafactory/v1/plugins/model_plugins/parallelization/ulysses.py:128— # TODO (Reza): change the api on the megatron-deepspeed side so that we only receive all data (q,k, and v) together! — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment src/llamafactory/v1/core/utils/batching.py:183— # TODO: support length and infinity — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment src/llamafactory/v1/core/utils/inference_engine.py:97— # TODO: configurable — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment src/llamafactory/train/mca/workflow.py:223— # TODO: FIX SequencePacking — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment src/llamafactory/model/model_utils/quantization.py:76— # TODO: fix large maxlen — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment src/llamafactory/data/collator.py:454— # TODO: support omni models for packed sequences @kuangdd — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
TodoComment src/llamafactory/data/processor/supervised.py:148— # TODO: use `position_ids` to achieve packing — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
Swallowed exception (caught, then discarded) src/llamafactory/webui/common.py:79— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) src/llamafactory/webui/common.py:159— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) src/llamafactory/v1/plugins/model_plugins/kernels/ops/rms_norm/supa_rms_norm.py:66— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) src/llamafactory/train/trainer_utils.py:876— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) src/llamafactory/train/megatron_bridge/dataset_export.py:46— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) src/llamafactory/train/megatron_bridge/dataset_export.py:201— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) src/llamafactory/train/megatron_bridge/workflow.py:219— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) REDACTED:49— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) REDACTED:61— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (caught, then discarded) src/llamafactory/data/tool_utils.py:640— `except Exception` takes every exception and records none of it — the body neither logs it, rethrows it, nor even names it, so the failure is discarded as completely as by an empty catch and only the substituted value survives. Log it through whatever this codebase already uses to report problems, narrow the catch to the exception this call can actually raise, or say in a comment on the catch why the failure genuinely cannot matter.
Swallowed exception (empty catch) src/llamafactory/webui/common.py:55— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) src/llamafactory/train/callbacks.py:401— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) src/llamafactory/extras/env.py:57— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) src/llamafactory/extras/env.py:74— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) src/llamafactory/extras/env.py:81— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) src/llamafactory/extras/env.py:88— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) src/llamafactory/extras/env.py:95— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) src/llamafactory/extras/env.py:104— An empty catch block silently discards the error — failures vanish with no log and no rethrow. Log it, handle it, or don't catch it.
Swallowed exception (empty catch) src/llamafactory/chat/sglang_engine.py:291— An empty catch block silently discards the error — failures vanish with no log and no rethrow. On a teardown path letting it propagate is not an option (throwing out of `__del__()` masks the failure already in flight and abandons the rest of the cleanup), so make the swallow deliberate instead: narrow the catch to the exception this release can actually raise, and record it through whatever this codebase already uses to report problems — or, if it truly cannot matter, say why in a comment on the catch.
Change coupling: workflow.py ↔ workflow.py src/llamafactory/train/pt/workflow.py:1— `src/llamafactory/train/pt/workflow.py` and `src/llamafactory/train/sft/workflow.py` change together 81% of the time (22 of the 27 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency — the edge is real but nothing declares it. Read the pair before acting: if one registers itself into the other through a hook or an initialiser, the missing dependency is DELIBERATE — the registration is the link, and it is meant not to be an import — and the thing to add is a comment on each side naming the other, not a merge; if they simply belong together, co-locate them; if neither holds, the coupling is hidden and worth breaking. You can check this without leaving the row: of the 22 shared commits counted here, the most recent 3 are `acb09fa3` [trainer] fix key error (#7635); `af178cbc` update get template; `e4d11a11` fix up — run `git show` on any of them.
Change coupling: workflow.py ↔ workflow.py src/llamafactory/train/kto/workflow.py:1— `src/llamafactory/train/kto/workflow.py` and `src/llamafactory/train/sft/workflow.py` change together 73% of the time (8 of the 11 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency — the edge is real but nothing declares it. Read the pair before acting: if one registers itself into the other through a hook or an initialiser, the missing dependency is DELIBERATE — the registration is the link, and it is meant not to be an import — and the thing to add is a comment on each side naming the other, not a merge; if they simply belong together, co-locate them; if neither holds, the coupling is hidden and worth breaking. You can check this without leaving the row: of the 8 shared commits counted here, the most recent 3 are `416853dd` [parser] support omegaconf (#7793); `acb09fa3` [trainer] fix key error (#7635); `fb22651f` fix mrope — run `git show` on any of them.
Change coupling: workflow.py ↔ workflow.py src/llamafactory/train/ppo/workflow.py:1— `src/llamafactory/train/ppo/workflow.py` and `src/llamafactory/train/pt/workflow.py` change together 67% of the time (18 of the 27 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency — the edge is real but nothing declares it. Read the pair before acting: if one registers itself into the other through a hook or an initialiser, the missing dependency is DELIBERATE — the registration is the link, and it is meant not to be an import — and the thing to add is a comment on each side naming the other, not a merge; if they simply belong together, co-locate them; if neither holds, the coupling is hidden and worth breaking. You can check this without leaving the row: of the 18 shared commits counted here, the most recent 3 are `af178cbc` update get template; `e4d11a11` fix up; `5f2bd047` 1. add custom eval dataset support 2. merge load dataset and split da… — run `git show` on any of them.
Change coupling: chatter.py ↔ chatbot.py src/llamafactory/webui/chatter.py:1— `src/llamafactory/webui/chatter.py` and `src/llamafactory/webui/components/chatbot.py` change together 61% of the time (11 of the 18 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency — the edge is real but nothing declares it. Read the pair before acting: if one registers itself into the other through a hook or an initialiser, the missing dependency is DELIBERATE — the registration is the link, and it is meant not to be an import — and the thing to add is a comment on each side naming the other, not a merge; if they simply belong together, co-locate them; if neither holds, the coupling is hidden and worth breaking. You can check this without leaving the row: of the 11 shared commits counted here, the most recent 3 are `5987a8dd` [webui] add seed controls for reproducibility (#10629); `052ca871` [data] optimize qwen3 loss computation (#7923); `26357947` [webui] support escape html (#7190) — run `git show` on any of them.
Change coupling: eval.py ↔ runner.py src/llamafactory/webui/components/eval.py:1— `src/llamafactory/webui/components/eval.py` and `src/llamafactory/webui/runner.py` change together 57% of the time (12 of the 21 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency — the edge is real but nothing declares it. Read the pair before acting: if one registers itself into the other through a hook or an initialiser, the missing dependency is DELIBERATE — the registration is the link, and it is meant not to be an import — and the thing to add is a comment on each side naming the other, not a merge; if they simply belong together, co-locate them; if neither holds, the coupling is hidden and worth breaking. You can check this without leaving the row: of the 12 shared commits counted here, the most recent 3 are `5987a8dd` [webui] add seed controls for reproducibility (#10629); `26bc79f9` fix #4043; `182b9747` fix eval in webui (at that commit the files were still `src/llmtuner/webui/components/eval.py` and `src/llmtuner/webui/runner.py`) — run `git show` on any of them.
Change coupling: top.py ↔ runner.py src/llamafactory/webui/components/top.py:1— `src/llamafactory/webui/components/top.py` and `src/llamafactory/webui/runner.py` change together 56% of the time (19 of the 34 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency — the edge is real but nothing declares it. Read the pair before acting: if one registers itself into the other through a hook or an initialiser, the missing dependency is DELIBERATE — the registration is the link, and it is meant not to be an import — and the thing to add is a comment on each side naming the other, not a merge; if they simply belong together, co-locate them; if neither holds, the coupling is hidden and worth breaking. You can check this without leaving the row: of the 19 shared commits counted here, the most recent 3 are `87d685b5` [model] support yarn (#6693); `31daa657` [webui] upgrade to gradio 5 (#6688); `aeeee9d4` support extra args in llamaboard — run `git show` on any of them.
Change coupling: top.py ↔ locales.py src/llamafactory/webui/components/top.py:1— `src/llamafactory/webui/components/top.py` and `src/llamafactory/webui/locales.py` change together 53% of the time (18 of the 34 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency — the edge is real but nothing declares it. Read the pair before acting: if one registers itself into the other through a hook or an initialiser, the missing dependency is DELIBERATE — the registration is the link, and it is meant not to be an import — and the thing to add is a comment on each side naming the other, not a merge; if they simply belong together, co-locate them; if neither holds, the coupling is hidden and worth breaking. You can check this without leaving the row: of the 18 shared commits counted here, the most recent 3 are `dc080399` [model] add seed coder and qwen3 quant models (#8039); `db9b977e` [webui] support ja (#6698); `87d685b5` [model] support yarn (#6693) — run `git show` on any of them.
Change coupling: __init__.py ↔ packing.py src/llamafactory/__init__.py:1— `src/llamafactory/__init__.py` and `src/llamafactory/model/model_utils/packing.py` change together 50% of the time (13 of the 26 commits that touched whichever of the two files changed less often, counting a file under its earlier names as well — a repo-wide or module-wide sweep is evidence about the sweep rather than about any pair inside it and is left out of BOTH sides of this ratio, while a dependency bump, a formatter/rename sweep, or a commit whose edit to one of the two files was a tool directive such as //go:generate or whitespace only is left out of the shared count ONLY, so the two sides are not taken over identical commit sets) with no explicit dependency — the edge is real but nothing declares it. Read the pair before acting: if one registers itself into the other through a hook or an initialiser, the missing dependency is DELIBERATE — the registration is the link, and it is meant not to be an import — and the thing to add is a comment on each side naming the other, not a merge; if they simply belong together, co-locate them; if neither holds, the coupling is hidden and worth breaking. You can check this without leaving the row: of the 13 shared commits counted here, the most recent 3 are `39169986` [trainer] fix pt loss (#7748); `86ebb219` [breaking] bump transformers to 4.45.0 & improve ci (#7746); `4d1791e9` [deps] upgrade vllm (#6857) — run `git show` on any of them.
Hotspot: src/llamafactory/model/patcher.py src/llamafactory/model/patcher.py:440— src/llamafactory/model/patcher.py changed 5 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 23 in patcher.patch_model at line 440. 1 of those changes was a fix/bug commit, and the other 4 changed it for other reasons — this file is under both repair and feature pressure. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 21:16:47 +08:00' --until='2026-11-13 21:16:47 +08:00' --full-history --no-merges -- src/llamafactory/model/patcher.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: src/llamafactory/model/model_utils/liger_kernel.py src/llamafactory/model/model_utils/liger_kernel.py:31— src/llamafactory/model/model_utils/liger_kernel.py changed 2 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 35 in liger_kernel.apply_liger_kernel at line 31. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 21:16:47 +08:00' --until='2026-11-13 21:16:47 +08:00' --full-history --no-merges -- src/llamafactory/model/model_utils/liger_kernel.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py:351— src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py changed 3 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 21 in FSDPTurboFSDP2Engine.prepare_model_ep at line 351. 2 of those changes were fix/bug commits, so the churn is repair rather than feature work. Before the next change lands here, make sure the area it touches is under test, then split that area out of the file so the following change is smaller than this one — a file this often edited pays the complexity back every time. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 21:16:47 +08:00' --until='2026-11-13 21:16:47 +08:00' --full-history --no-merges -- src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: src/llamafactory/model/model_utils/moe.py src/llamafactory/model/model_utils/moe.py:43— src/llamafactory/model/model_utils/moe.py changed 2 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 27 in moe.add_z3_leaf_module at line 43. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 21:16:47 +08:00' --until='2026-11-13 21:16:47 +08:00' --full-history --no-merges -- src/llamafactory/model/model_utils/moe.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: src/llamafactory/model/model_utils/attention.py src/llamafactory/model/model_utils/attention.py:32— src/llamafactory/model/model_utils/attention.py changed 2 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 26 in attention.configure_attn_implementation at line 32. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 21:16:47 +08:00' --until='2026-11-13 21:16:47 +08:00' --full-history --no-merges -- src/llamafactory/model/model_utils/attention.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: src/llamafactory/v1/core/base_trainer.py src/llamafactory/v1/core/base_trainer.py:250— src/llamafactory/v1/core/base_trainer.py changed 3 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 17 in BaseTrainer.fit at line 250. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 21:16:47 +08:00' --until='2026-11-13 21:16:47 +08:00' --full-history --no-merges -- src/llamafactory/v1/core/base_trainer.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
Hotspot: src/llamafactory/hparams/parser.py src/llamafactory/hparams/parser.py:272— src/llamafactory/hparams/parser.py changed 2 times in last 90 days, and the most complex body those changes touched has cyclomatic complexity 18 in parser._check_extra_dependencies at line 272. Frequent change and high complexity in one file compound: schedule the next change to it to include carving out the part being edited, with the area under test before it moves. Counted over 2026-08-15..2026-11-13, the 90 days ending at the analysed commit. Reproduce with `git log --since='2026-08-15 21:16:47 +08:00' --until='2026-11-13 21:16:47 +08:00' --full-history --no-merges -- src/llamafactory/hparams/parser.py`: merges are excluded because a merge re-states changes already counted at their own commits, and history is NOT path-simplified because a change that reached the file through a merged branch is still a change to it. That command counts raw commits and can read HIGHER than this row, which counts a cherry-picked re-land, and a revert together with the commit it undoes, once each — a difference of several commits on a file whose history was re-landed or reverted inside the window.
FileTooLong: data/mm_plugin.py src/llamafactory/data/mm_plugin.py— FileTooLong — 2716 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 2216 over it, 5.43× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: extras/constants.py src/llamafactory/extras/constants.py— FileTooLong — 2490 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1990 over it, 4.98× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: data/template.py src/llamafactory/data/template.py— FileTooLong — 1979 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 1479 over it, 3.96× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: data/tool_utils.py src/llamafactory/data/tool_utils.py— FileTooLong — 823 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 323 over it, 1.65× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: distributed/fsdp2.py src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py— FileTooLong — 561 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 61 over it, 1.12× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: train/trainer_utils.py src/llamafactory/train/trainer_utils.py— FileTooLong — 547 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 47 over it, 1.09× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
FileTooLong: hparams/parser.py src/llamafactory/hparams/parser.py— FileTooLong — 530 significant lines (blank, comment-only and punctuation-only lines excluded). The bar is 500 significant lines; this is 30 over it, 1.06× the bar. To reduce it, split the file along the responsibilities already in it: move each cohesive group of declarations into its own sibling file in the same module or package, so no one file has to be read whole to change one of them.
Duplicated block (8 lines × 2) src/llamafactory/data/converter.py:410— src/llamafactory/data/converter.py:410-417 | src/llamafactory/data/loader.py:246-253 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (8 lines × 2) src/llamafactory/data/mm_plugin.py:2563— src/llamafactory/data/mm_plugin.py:2563-2570 | src/llamafactory/data/mm_plugin.py:3034-3041 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `src/llamafactory/data/mm_plugin.py:2571` calls `_get_mm_token_metadata` and `src/llamafactory/data/mm_plugin.py:3042` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (8 lines × 2) src/llamafactory/data/tool_utils.py:540— src/llamafactory/data/tool_utils.py:540-547 | src/llamafactory/data/tool_utils.py:743-750 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8 lines × 2) src/llamafactory/train/dpo/trainer.py:337— src/llamafactory/train/dpo/trainer.py:337-344 | src/llamafactory/train/kto/trainer.py:289-296 — `src/llamafactory/train/dpo/trainer.py` and `src/llamafactory/train/kto/trainer.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 4 separate duplicated blocks between them, totalling at least 65 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (8 lines × 2) src/llamafactory/train/trainer_utils.py:664— src/llamafactory/train/trainer_utils.py:664-671 | src/llamafactory/train/trainer_utils.py:797-804 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (8 lines × 2) src/llamafactory/v1/trainers/dpo_trainer.py:120— src/llamafactory/v1/trainers/dpo_trainer.py:120-127 | src/llamafactory/v1/trainers/rm_trainer.py:87-94 — before extracting anything, compare `src/llamafactory/v1/trainers/dpo_trainer.py` and `src/llamafactory/v1/trainers/rm_trainer.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 31 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (8 lines × 2) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:523— src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:523-530 | src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:533-540 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (6 lines × 2) src/llamafactory/webui/chatter.py:131— src/llamafactory/webui/chatter.py:131-136 | src/llamafactory/webui/runner.py:145-150 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (6 lines × 2) scripts/eval_bleu_rouge.py:45— scripts/eval_bleu_rouge.py:45-50 | src/llamafactory/train/sft/metric.py:120-125 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (6 lines × 2) src/api.py:24— src/api.py:24-29 | REDACTED:128-133 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Note first that the copies are not typed on the same thing: `ChatModel` names `..chat` in one and `llamafactory.chat` in another — different types that share a simple name, which is why the text matched. A single extracted unit cannot be given a parameter type that fits both, so unifying those types (or introducing a shared abstraction over them) is the step that has to come BEFORE the extraction above; if they are deliberately separate, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (6 lines × 2) REDACTED:381— REDACTED:381-386 | REDACTED:20-25 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (6 lines × 2) src/llamafactory/train/rm/metric.py:32— src/llamafactory/train/rm/metric.py:32-37 | src/llamafactory/train/sft/metric.py:66-71 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (6 lines × 2) src/llamafactory/webui/interface.py:92— src/llamafactory/webui/interface.py:92-97 | src/webui.py:22-27 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (6 lines × 2) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:82— src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:82-87 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:210-215 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) src/llamafactory/data/converter.py:147— src/llamafactory/data/converter.py:147-155 | src/llamafactory/data/converter.py:241-249 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) src/llamafactory/model/patcher.py:115— src/llamafactory/model/patcher.py:115-125 | src/llamafactory/model/patcher.py:127-135 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) src/llamafactory/train/rm/workflow.py:74— src/llamafactory/train/rm/workflow.py:74-82 | src/llamafactory/train/sft/workflow.py:132-140 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (9 lines × 2) src/llamafactory/v1/plugins/data_plugins/converter.py:227— src/llamafactory/v1/plugins/data_plugins/converter.py:227-235 | src/llamafactory/v1/plugins/data_plugins/converter.py:289-297 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (9 lines × 2) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:142— src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:142-150 | src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:171-179 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (9 lines × 2) src/llamafactory/extras/logging.py:82— src/llamafactory/extras/logging.py:82-90 | src/llamafactory/v1/utils/logging.py:45-53 — before extracting anything, compare `src/llamafactory/extras/logging.py` and `src/llamafactory/v1/utils/logging.py` as WHOLE FILES: 87% of the shorter file's lines also appear in the other, so this reads as one file having been copied from the other rather than as a helper waiting to be extracted. The 2 duplicated block(s) this scan matched between them are fragments of that copy, not the extent of it — treat the file pair as the unit. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
HackComment src/llamafactory/train/sft/workflow.py:60— # hack here: make model compatible with prediction — a workaround marked in source: record what it is compensating for and what would allow its removal (the upstream fix, the API it is waiting on, the invariant it restores), so the next reader can judge whether it is still needed rather than rediscovering why it is there.
HackComment src/llamafactory/train/kto/trainer.py:63— # hack to avoid warning — a workaround marked in source: record what it is compensating for and what would allow its removal (the upstream fix, the API it is waiting on, the invariant it restores), so the next reader can judge whether it is still needed rather than rediscovering why it is there.
HackComment src/llamafactory/train/dpo/trainer.py:65— # hack to avoid warning — a workaround marked in source: record what it is compensating for and what would allow its removal (the upstream fix, the API it is waiting on, the invariant it restores), so the next reader can judge whether it is still needed rather than rediscovering why it is there.
HackComment src/llamafactory/data/loader.py:202— # hack datasets to have int32 attention mask — a workaround marked in source: record what it is compensating for and what would allow its removal (the upstream fix, the API it is waiting on, the invariant it restores), so the next reader can judge whether it is still needed rather than rediscovering why it is there.
HackComment src/llamafactory/data/mm_plugin.py:2301— # hack usage when do_sample_frames=False — a workaround marked in source: record what it is compensating for and what would allow its removal (the upstream fix, the API it is waiting on, the invariant it restores), so the next reader can judge whether it is still needed rather than rediscovering why it is there.
Duplicated block (13 lines × 2) src/llamafactory/chat/sglang_engine.py:180— src/llamafactory/chat/sglang_engine.py:180-192 | src/llamafactory/chat/vllm_engine.py:153-165 — before extracting anything, compare `src/llamafactory/chat/sglang_engine.py` and `src/llamafactory/chat/vllm_engine.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 47 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (13 lines × 2) src/llamafactory/data/mm_plugin.py:402— src/llamafactory/data/mm_plugin.py:402-414 | src/llamafactory/data/mm_plugin.py:3160-3172 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (13 lines × 2) src/llamafactory/data/mm_plugin.py:2578— src/llamafactory/data/mm_plugin.py:2578-2590 | src/llamafactory/data/mm_plugin.py:3210-3222 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (13 lines × 2) src/llamafactory/v1/trainers/dpo_trainer.py:72— src/llamafactory/v1/trainers/dpo_trainer.py:72-84 | src/llamafactory/v1/trainers/rm_trainer.py:34-46 — before extracting anything, compare `src/llamafactory/v1/trainers/dpo_trainer.py` and `src/llamafactory/v1/trainers/rm_trainer.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 31 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/v1/trainers/dpo_trainer.py:72` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (13 lines × 2) src/llamafactory/webui/runner.py:190— src/llamafactory/webui/runner.py:190-202 | src/llamafactory/webui/runner.py:339-351 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (11 lines × 2) src/llamafactory/data/mm_plugin.py:1621— src/llamafactory/data/mm_plugin.py:1621-1631 | src/llamafactory/data/mm_plugin.py:1827-1837 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/mm_plugin.py:1621` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (11 lines × 2) src/llamafactory/data/template.py:166— src/llamafactory/data/template.py:166-176 | src/llamafactory/data/template.py:653-663 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (11 lines × 2) src/llamafactory/train/mca/workflow.py:170— src/llamafactory/train/mca/workflow.py:170-180 | src/llamafactory/train/mca/workflow.py:227-237 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (11 lines × 2) src/llamafactory/webui/components/train.py:81— src/llamafactory/webui/components/train.py:81-91 | src/llamafactory/webui/components/train.py:228-238 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/webui/components/train.py:81` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (11 lines × 2) src/llamafactory/train/trainer_utils.py:642— src/llamafactory/train/trainer_utils.py:642-652 | src/llamafactory/train/trainer_utils.py:774-784 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) src/llamafactory/data/mm_plugin.py:283— src/llamafactory/data/mm_plugin.py:283-289 | src/llamafactory/data/mm_plugin.py:2281-2289 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (7 lines × 2) src/llamafactory/data/processor/feedback.py:59— src/llamafactory/data/processor/feedback.py:59-65 | src/llamafactory/data/processor/pairwise.py:50-56 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (7 lines × 2) src/llamafactory/model/model_utils/misc.py:43— src/llamafactory/model/model_utils/misc.py:43-49 | src/llamafactory/v1/plugins/model_plugins/peft.py:90-96 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note first that the copies are not typed on the same thing: the declarations holding them bind `model` to `"PreTrainedModel"` in one and `HFModel` in another, and the duplicated lines use it. The extracted unit therefore needs a parameter type that fits BOTH — their common supertype where they have one, or a new abstraction over them where they do not — and settling that is the step that comes BEFORE the extraction above. Where the two types are deliberately unrelated, the duplication is the price of that separation and the honest resolution is to record the decision rather than to extract.
Duplicated block (7 lines × 2) src/llamafactory/data/processor/feedback.py:88— src/llamafactory/data/processor/feedback.py:88-94 | src/llamafactory/data/processor/pairwise.py:73-79 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (7 lines × 2) scripts/eval_bleu_rouge.py:62— scripts/eval_bleu_rouge.py:62-68 | scripts/vllm_infer.py:254-260 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Outbound HTTP without resilience src/llamafactory/api/chat.py:131— `requests.get(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout.
Outbound HTTP without resilience src/llamafactory/api/chat.py:144— `requests.get(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout.
Outbound HTTP without resilience src/llamafactory/api/chat.py:157— `requests.get(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout.
Outbound HTTP without resilience src/llamafactory/chat/sglang_engine.py:220— `requests.post(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout.
Outbound HTTP without resilience src/llamafactory/train/ppo/ppo_utils.py:38— `requests.post(` makes an outbound HTTP call, and nothing bounds it: no timeout, deadline, retry or circuit breaker is set for it here, and the client has no process-wide default. A slow or failing dependency will hold this service's request, thread or connection until the call gives up on its own — or never, for a client with no default timeout.
FixmeComment src/llamafactory/data/collator.py:197— # FIXME: need to get video image lengths — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
FixmeComment src/llamafactory/data/collator.py:224— # FIXME: maybe right_padding_length is large, with improper max_cutoff_len — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
FixmeComment src/llamafactory/data/collator.py:447— # FIXME: too tricky, need to be refactored @kuangdd — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
FixmeComment src/llamafactory/data/collator.py:548— # FIXME compatibility fa3/fa4 — source code is not a task system: move the work to your tracker and leave a reference instead (e.g. `# REF: #123`), so the task is planned where tasks live and the ticket links back to the code.
Duplicated block (16 lines × 2) src/llamafactory/chat/sglang_engine.py:66— src/llamafactory/chat/sglang_engine.py:66-81 | src/llamafactory/chat/vllm_engine.py:55-70 — before extracting anything, compare `src/llamafactory/chat/sglang_engine.py` and `src/llamafactory/chat/vllm_engine.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 47 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (16 lines × 2) REDACTED:94— REDACTED:94-109 | src/llamafactory/v1/utils/packages.py:54-69 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (16 lines × 2) src/llamafactory/train/dpo/trainer.py:64— src/llamafactory/train/dpo/trainer.py:64-79 | src/llamafactory/train/kto/trainer.py:62-77 — `src/llamafactory/train/dpo/trainer.py` and `src/llamafactory/train/kto/trainer.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 4 separate duplicated blocks between them, totalling at least 65 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (16 lines × 2) src/llamafactory/v1/core/utils/collation.py:124— src/llamafactory/v1/core/utils/collation.py:124-139 | src/llamafactory/v1/core/utils/collation.py:196-211 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Change-coupling hub: workflow.py → workflow.py, workflow.py, workflow.py, workflow.py, workflow.py src/llamafactory/train/rm/workflow.py— `src/llamafactory/train/rm/workflow.py` changes together with 5 other files — `src/llamafactory/train/dpo/workflow.py`, `src/llamafactory/train/kto/workflow.py`, `src/llamafactory/train/ppo/workflow.py`, `src/llamafactory/train/pt/workflow.py`, `src/llamafactory/train/sft/workflow.py` — none of which declares a dependency on it: one file is the hub of 5 separate couplings, not 5 unrelated pairs. Read the hub first: if the others each duplicate a part of what it does, the shared concern belongs in ONE unit and extracting it clears every edge at once; if the hub is a registry, dispatcher or barrel that must name each of them, the coupling is structural and the question is whether that list can be discovered instead of enumerated. Fixing the hub is one change; breaking the couplings one pair at a time is 5.
Change-coupling hub: workflow.py → workflow.py, workflow.py, workflow.py src/llamafactory/train/dpo/workflow.py— `src/llamafactory/train/dpo/workflow.py` changes together with 3 other files — `src/llamafactory/train/kto/workflow.py`, `src/llamafactory/train/pt/workflow.py`, `src/llamafactory/train/sft/workflow.py` — none of which declares a dependency on it: one file is the hub of 3 separate couplings, not 3 unrelated pairs. Read the hub first: if the others each duplicate a part of what it does, the shared concern belongs in ONE unit and extracting it clears every edge at once; if the hub is a registry, dispatcher or barrel that must name each of them, the coupling is structural and the question is whether that list can be discovered instead of enumerated. Fixing the hub is one change; breaking the couplings one pair at a time is 3.
Change-coupling hub: train.py → eval.py, locales.py, runner.py src/llamafactory/webui/components/train.py— `src/llamafactory/webui/components/train.py` changes together with 3 other files — `src/llamafactory/webui/components/eval.py`, `src/llamafactory/webui/locales.py`, `src/llamafactory/webui/runner.py` — none of which declares a dependency on it: one file is the hub of 3 separate couplings, not 3 unrelated pairs. Read the hub first: if the others each duplicate a part of what it does, the shared concern belongs in ONE unit and extracting it clears every edge at once; if the hub is a registry, dispatcher or barrel that must name each of them, the coupling is structural and the question is whether that list can be discovered instead of enumerated. Fixing the hub is one change; breaking the couplings one pair at a time is 3.
D4 · Code Duplication· Edited copy of a member (19 corresponding lines) · ×3
Edited copy of a member (19 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/npu_fused_moe.py:215— src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/npu_fused_moe.py:215-239 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/npu_fused_moe.py:330-348 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:310— src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:310-331 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/npu_fused_moe.py:243-261 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (19 corresponding lines) src/llamafactory/chat/hf_engine.py:356— src/llamafactory/chat/hf_engine.py:356-374 | src/llamafactory/chat/hf_engine.py:387-410 — These two members are one piece of code written twice and then edited apart: 19 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (25 lines × 2) src/llamafactory/train/hyper_parallel/workflow.py:237— src/llamafactory/train/hyper_parallel/workflow.py:237-261 | src/llamafactory/train/sft/workflow.py:110-134 — `src/llamafactory/train/hyper_parallel/workflow.py` and `src/llamafactory/train/sft/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 6 separate duplicated blocks between them, totalling at least 101 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/train/hyper_parallel/workflow.py:237` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (25 lines × 2) src/llamafactory/train/hyper_parallel/workflow.py:264— src/llamafactory/train/hyper_parallel/workflow.py:264-288 | src/llamafactory/train/sft/workflow.py:136-160 — `src/llamafactory/train/hyper_parallel/workflow.py` and `src/llamafactory/train/sft/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 6 separate duplicated blocks between them, totalling at least 101 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/train/hyper_parallel/workflow.py:264` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (25 lines × 2) src/llamafactory/train/megatron_bridge/config_builder.py:589— src/llamafactory/train/megatron_bridge/config_builder.py:589-613 | src/llamafactory/train/megatron_bridge/config_builder.py:650-674 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/train/megatron_bridge/config_builder.py:589` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (17 lines × 2) src/llamafactory/extras/logging.py:102— src/llamafactory/extras/logging.py:102-118 | src/llamafactory/v1/utils/logging.py:65-81 — before extracting anything, compare `src/llamafactory/extras/logging.py` and `src/llamafactory/v1/utils/logging.py` as WHOLE FILES: 87% of the shorter file's lines also appear in the other, so this reads as one file having been copied from the other rather than as a helper waiting to be extracted. The 2 duplicated block(s) this scan matched between them are fragments of that copy, not the extent of it — treat the file pair as the unit. The two sit in different directories, so one cannot simply be deleted in favour of the other while both are reached separately: hoist the shared part into a location both already depend on and have each file call it, and retire whichever file turns out to have no caller of its own left. Extracting one helper per block leaves the fork in place. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (17 lines × 2) src/llamafactory/train/hyper_parallel/workflow.py:102— src/llamafactory/train/hyper_parallel/workflow.py:102-118 | src/llamafactory/train/hyper_parallel/workflow.py:181-197 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (17 lines × 2) scripts/stat_utils/cal_lr.py:55— scripts/stat_utils/cal_lr.py:55-71 | scripts/stat_utils/cal_ppl.py:75-91 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `scripts/stat_utils/cal_lr.py:55` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `scripts/stat_utils/cal_ppl.py:92` calls `load_model` and `scripts/stat_utils/cal_lr.py:72` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (15 lines × 3) src/llamafactory/train/dpo/workflow.py:75— src/llamafactory/train/dpo/workflow.py:75-89 | src/llamafactory/train/hyper_parallel/workflow.py:242-256 | src/llamafactory/train/sft/workflow.py:115-129 — `src/llamafactory/train/dpo/workflow.py` and `src/llamafactory/train/hyper_parallel/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 3 separate duplicated blocks between them, totalling at least 35 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/train/dpo/workflow.py:75` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (15 lines × 3) src/llamafactory/webui/components/chatbot.py:126— src/llamafactory/webui/components/chatbot.py:126-140 | src/llamafactory/webui/components/train.py:154-168 | src/llamafactory/webui/components/train.py:420-434 — there are 3 copies across 2 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 3 sites; resolving a subset leaves the remainder to drift apart. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/webui/components/chatbot.py:126` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `src/llamafactory/webui/components/train.py:153` calls `update` and `src/llamafactory/webui/components/chatbot.py:125` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (15 lines × 3) src/llamafactory/webui/components/train.py:303— src/llamafactory/webui/components/train.py:303-317 | src/llamafactory/webui/components/train.py:323-337 | src/llamafactory/webui/components/train.py:343-357 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `src/llamafactory/webui/components/train.py:338` calls `Dropdown` and `src/llamafactory/webui/components/train.py:318` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (10 lines × 2) src/llamafactory/api/chat.py:137— src/llamafactory/api/chat.py:137-146 | src/llamafactory/api/chat.py:150-159 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (10 lines × 2) src/llamafactory/data/tool_utils.py:465— src/llamafactory/data/tool_utils.py:465-474 | src/llamafactory/data/tool_utils.py:670-679 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (10 lines × 2) src/llamafactory/data/tool_utils.py:808— src/llamafactory/data/tool_utils.py:808-817 | src/llamafactory/data/tool_utils.py:953-962 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (5 lines × 2) scripts/bench_qwen.py:85— scripts/bench_qwen.py:85-89 | src/llamafactory/data/collator.py:156-160 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `src/llamafactory/data/collator.py:153` calls `getattr` and `scripts/bench_qwen.py:82` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (5 lines × 2) src/llamafactory/train/callbacks.py:146— src/llamafactory/train/callbacks.py:146-150 | src/llamafactory/train/callbacks.py:160-168 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `src/llamafactory/train/callbacks.py:158` calls `join` and `src/llamafactory/train/callbacks.py:145` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (5 lines × 2) src/llamafactory/webui/interface.py:66— src/llamafactory/webui/interface.py:66-70 | src/llamafactory/webui/interface.py:84-88 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
workflow.run_pt (cognitive 22) src/llamafactory/train/hyper_parallel/workflow.py:95— workflow.run_pt has cognitive complexity 22 (threshold 15). Drivers by points: if/else 7 (11 pts), error handling 2 (7 pts), loops 1 (3 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
workflow.run_pt (cognitive 22) src/llamafactory/train/pt/workflow.py:36— workflow.run_pt has cognitive complexity 22 (threshold 15). Drivers by points: if/else 7 (11 pts), error handling 2 (7 pts), loops 1 (3 pts), boolean chains 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
launcher.launch (cognitive 19) REDACTED:38— launcher.launch has cognitive complexity 19 (threshold 15). Drivers by points: if/else 8 (13 pts), boolean chains 5, ternaries 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
launcher.launch (cognitive 19) REDACTED:34— launcher.launch has cognitive complexity 19 (threshold 15). Drivers by points: if/else 8 (14 pts), boolean chains 4, ternaries 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
D4 · Code Duplication· Edited copy of a member (43 corresponding lines) · ×2
Edited copy of a member (43 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:82— src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:82-136 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:210-252 — These two members are one piece of code written twice and then edited apart: 43 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (43 corresponding lines) scripts/loftq_init.py:41— scripts/loftq_init.py:41-84 | scripts/pissa_init.py:40-82 — These two members are one piece of code written twice and then edited apart: 43 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (14 corresponding lines) · ×2
Edited copy of a member (14 corresponding lines) src/llamafactory/train/trainer_utils.py:642— src/llamafactory/train/trainer_utils.py:642-655 | src/llamafactory/train/trainer_utils.py:774-787 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (14 corresponding lines) src/llamafactory/data/tool_utils.py:808— src/llamafactory/data/tool_utils.py:808-821 | src/llamafactory/data/tool_utils.py:953-967 — These two members are one piece of code written twice and then edited apart: 14 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (28 corresponding lines) · ×2
Edited copy of a member (28 corresponding lines) src/llamafactory/v1/plugins/trainer_plugins/batching.py:61— src/llamafactory/v1/plugins/trainer_plugins/batching.py:61-89 | src/llamafactory/v1/plugins/trainer_plugins/batching.py:93-120 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (28 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:322— src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:322-349 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:390-417 — These two members are one piece of code written twice and then edited apart: 28 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (17 corresponding lines) · ×2
Edited copy of a member (17 corresponding lines) src/llamafactory/data/mm_plugin.py:313— src/llamafactory/data/mm_plugin.py:313-329 | src/llamafactory/v1/core/rendering/format.py:130-146 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (17 corresponding lines) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:444— src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:444-463 | src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py:445-461 — These two members are one piece of code written twice and then edited apart: 17 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (6 corresponding lines) · ×2
Edited copy of a member (6 corresponding lines) src/llamafactory/train/dpo/trainer.py:151— src/llamafactory/train/dpo/trainer.py:151-158 | src/llamafactory/v1/trainers/dpo_trainer.py:337-342 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (6 corresponding lines) src/llamafactory/chat/vllm_engine.py:260— src/llamafactory/chat/vllm_engine.py:260-265 | src/llamafactory/chat/sglang_engine.py:271-276 — These two members are one piece of code written twice and then edited apart: 6 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (3 corresponding lines) · ×2
Edited copy of a member (3 corresponding lines) src/llamafactory/hparams/finetuning_args.py:662— src/llamafactory/hparams/finetuning_args.py:662-664 | src/llamafactory/hparams/model_args.py:788-790 — These two members are one piece of code written twice and then edited apart: 3 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Edited copy of a member (3 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/liger_kernel_ops.py:50— src/llamafactory/v1/plugins/model_plugins/kernels/liger_kernel_ops.py:50-52 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/linear_attention/fla.py:46-48 — These two members are one piece of code written twice and then edited apart: 3 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (19–22 lines × 2) src/llamafactory/webui/components/train.py:152— src/llamafactory/webui/components/train.py:152-173 | src/llamafactory/webui/components/train.py:419-437 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/webui/components/train.py:152` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (19–22 lines × 2) scripts/loftq_init.py:65— scripts/loftq_init.py:65-83 | scripts/pissa_init.py:57-78 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. Read the line range as the matched WINDOW rather than a finished unit: at `scripts/pissa_init.py:57` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (19 lines × 2) src/llamafactory/data/mm_plugin.py:1478— src/llamafactory/data/mm_plugin.py:1478-1496 | src/llamafactory/data/mm_plugin.py:1517-1535 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (19 lines × 2) src/llamafactory/data/mm_plugin.py:1667— src/llamafactory/data/mm_plugin.py:1667-1685 | src/llamafactory/data/mm_plugin.py:1924-1942 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (15–17 lines × 2) src/llamafactory/data/mm_plugin.py:2569— src/llamafactory/data/mm_plugin.py:2569-2583 | src/llamafactory/data/mm_plugin.py:2723-2739 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `src/llamafactory/data/mm_plugin.py:2720` calls `getattr` and `src/llamafactory/data/mm_plugin.py:2567` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (15–17 lines × 2) src/llamafactory/train/hyper_parallel/workflow.py:212— src/llamafactory/train/hyper_parallel/workflow.py:212-226 | src/llamafactory/train/sft/workflow.py:82-98 — `src/llamafactory/train/hyper_parallel/workflow.py` and `src/llamafactory/train/sft/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 6 separate duplicated blocks between them, totalling at least 101 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (14 lines × 2) src/llamafactory/train/mca/workflow.py:185— src/llamafactory/train/mca/workflow.py:185-198 | src/llamafactory/train/mca/workflow.py:252-265 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/train/mca/workflow.py:185` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (14 lines × 2) src/llamafactory/v1/core/rendering/format.py:50— src/llamafactory/v1/core/rendering/format.py:50-63 | src/llamafactory/v1/core/rendering/format.py:76-89 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/v1/core/rendering/format.py:50` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (9 lines × 3) src/llamafactory/data/mm_plugin.py:1706— src/llamafactory/data/mm_plugin.py:1706-1714 | src/llamafactory/data/mm_plugin.py:1941-1949 | src/llamafactory/data/mm_plugin.py:1956-1964 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (9 lines × 3) src/llamafactory/train/dpo/trainer.py:101— src/llamafactory/train/dpo/trainer.py:101-109 | src/llamafactory/train/kto/trainer.py:103-111 | src/llamafactory/train/sft/trainer.py:98-106 — `src/llamafactory/train/dpo/trainer.py` and `src/llamafactory/train/kto/trainer.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 4 separate duplicated blocks between them, totalling at least 65 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (7 lines × 3) src/llamafactory/data/mm_plugin.py:386— src/llamafactory/data/mm_plugin.py:386-392 | src/llamafactory/data/mm_plugin.py:1212-1218 | src/llamafactory/data/mm_plugin.py:1594-1600 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (7 lines × 3) src/llamafactory/train/hyper_parallel/workflow.py:253— src/llamafactory/train/hyper_parallel/workflow.py:253-261 | src/llamafactory/train/rm/workflow.py:70-76 | src/llamafactory/train/sft/workflow.py:126-134 — `src/llamafactory/train/hyper_parallel/workflow.py` and `src/llamafactory/train/sft/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 6 separate duplicated blocks between them, totalling at least 101 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/train/hyper_parallel/workflow.py:253` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (4–6 lines × 3) src/llamafactory/chat/hf_engine.py:130— src/llamafactory/chat/hf_engine.py:130-135 | src/llamafactory/chat/sglang_engine.py:170-173 | src/llamafactory/chat/vllm_engine.py:146-151 — before extracting anything, compare `src/llamafactory/chat/sglang_engine.py` and `src/llamafactory/chat/vllm_engine.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 47 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `src/llamafactory/chat/sglang_engine.py:169` calls `pop` and `src/llamafactory/chat/hf_engine.py:129` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (4–6 lines × 3) src/llamafactory/model/model_utils/longlora.py:100— src/llamafactory/model/model_utils/longlora.py:100-105 | src/llamafactory/model/model_utils/longlora.py:206-209 | src/llamafactory/model/model_utils/longlora.py:308-313 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/model/model_utils/longlora.py:100` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Low cohesion: HyperParallelTrainer (LCOM4 7) src/llamafactory/train/hyper_parallel/trainer.py:345— HyperParallelTrainer's methods fall into 7 groups that share no field and call none of each other, against a bar of more than 3 for this run (LCOM4, configurable — your repository's bar is the one quoted here). Each group is a set of methods reachable from one another through shared fields or direct calls, so 7 groups means the type has that many internally-connected clusters with nothing tying them together. Types whose shape makes a high count expected — and which would otherwise dominate this list — are excluded before this row is raised, so this is a genuine split candidate rather than a metric reading. It is still a shape, not a defect: confirm the groups match responsibilities you can name before splitting.
Low cohesion: CustomKTOTrainer (LCOM4 4) src/llamafactory/train/kto/trainer.py:43— CustomKTOTrainer's methods fall into 4 groups that share no field and call none of each other, against a bar of more than 3 for this run (LCOM4, configurable — your repository's bar is the one quoted here). Each group is a set of methods reachable from one another through shared fields or direct calls, so 4 groups means the type has that many internally-connected clusters with nothing tying them together. Types whose shape makes a high count expected — and which would otherwise dominate this list — are excluded before this row is raised, so this is a genuine split candidate rather than a metric reading. It is still a shape, not a defect: confirm the groups match responsibilities you can name before splitting.
parser.get_train_args (cyclomatic 112) src/llamafactory/hparams/parser.py:418— parser.get_train_args has cyclomatic complexity 112 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
adapter._setup_lora_tuning (cyclomatic 47) src/llamafactory/model/adapter.py:147— adapter._setup_lora_tuning has cyclomatic complexity 47 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
liger_kernel.apply_liger_kernel (cyclomatic 35) src/llamafactory/model/model_utils/liger_kernel.py:31— liger_kernel.apply_liger_kernel has cyclomatic complexity 35 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
OpenAIDatasetConverter.__call__ (cyclomatic 34) src/llamafactory/data/converter.py:232— OpenAIDatasetConverter.__call__ has cyclomatic complexity 34 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
quantization.configure_quantization (cyclomatic 34) src/llamafactory/model/model_utils/quantization.py:86— quantization.configure_quantization has cyclomatic complexity 34 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
HuggingfaceEngine._process_args (cyclomatic 33) src/llamafactory/chat/hf_engine.py:73— HuggingfaceEngine._process_args has cyclomatic complexity 33 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
chat._process_request (cyclomatic 32) src/llamafactory/api/chat.py:73— chat._process_request has cyclomatic complexity 32 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
MultiModalDataCollatorForSeq2Seq.__call__ (cyclomatic 31) src/llamafactory/data/collator.py:336— MultiModalDataCollatorForSeq2Seq.__call__ has cyclomatic complexity 31 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
tuner._training_function (cyclomatic 31) src/llamafactory/train/tuner.py:69— tuner._training_function has cyclomatic complexity 31 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
VllmEngine._generate (cyclomatic 30) src/llamafactory/chat/vllm_engine.py:111— VllmEngine._generate has cyclomatic complexity 30 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
loader.load_model (cyclomatic 29) src/llamafactory/model/loader.py:138— loader.load_model has cyclomatic complexity 29 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Runner._parse_train_args (cyclomatic 28) src/llamafactory/webui/runner.py:133— Runner._parse_train_args has cyclomatic complexity 28 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
PackedSupervisedDatasetProcessor.preprocess_dataset (cyclomatic 27) src/llamafactory/data/processor/supervised.py:147— PackedSupervisedDatasetProcessor.preprocess_dataset has cyclomatic complexity 27 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
moe.add_z3_leaf_module (cyclomatic 27) src/llamafactory/model/model_utils/moe.py:43— moe.add_z3_leaf_module has cyclomatic complexity 27 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
patcher.patch_config (cyclomatic 27) src/llamafactory/model/patcher.py:365— patcher.patch_config has cyclomatic complexity 27 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
SGLangEngine._generate (cyclomatic 26) src/llamafactory/chat/sglang_engine.py:140— SGLangEngine._generate has cyclomatic complexity 26 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
adapter._setup_freeze_tuning (cyclomatic 26) src/llamafactory/model/adapter.py:57— adapter._setup_freeze_tuning has cyclomatic complexity 26 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
attention.configure_attn_implementation (cyclomatic 26) src/llamafactory/model/model_utils/attention.py:32— attention.configure_attn_implementation has cyclomatic complexity 26 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
FinetuningArguments.__post_init__ (cyclomatic 25) src/llamafactory/hparams/finetuning_args.py:602— FinetuningArguments.__post_init__ has cyclomatic complexity 25 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
MultiModalDataCollatorForSeq2Seq._compute_rope_position_ids_with_packing (cyclomatic 24) src/llamafactory/data/collator.py:206— MultiModalDataCollatorForSeq2Seq._compute_rope_position_ids_with_packing has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
peft.get_freeze_model (cyclomatic 24) src/llamafactory/v1/plugins/model_plugins/peft.py:207— peft.get_freeze_model has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
FSDP2Engine._load_weights_from_hf_checkpoint (cyclomatic 24) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:509— FSDP2Engine._load_weights_from_hf_checkpoint has cyclomatic complexity 24 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
loader._load_single_dataset (cyclomatic 23) src/llamafactory/data/loader.py:51— loader._load_single_dataset has cyclomatic complexity 23 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
launcher.launch (cyclomatic 23) REDACTED:38— launcher.launch has cyclomatic complexity 23 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
patcher.patch_model (cyclomatic 23) src/llamafactory/model/patcher.py:440— patcher.patch_model has cyclomatic complexity 23 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
workflow.run_sft (cyclomatic 23) src/llamafactory/train/sft/workflow.py:41— workflow.run_sft has cyclomatic complexity 23 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
SharegptDatasetConverter.__call__ (cyclomatic 22) src/llamafactory/data/converter.py:136— SharegptDatasetConverter.__call__ has cyclomatic complexity 22 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Qwen2OmniPlugin.process_messages (cyclomatic 22) src/llamafactory/data/mm_plugin.py:3178— Qwen2OmniPlugin.process_messages has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
parser.get_dataset_list (cyclomatic 22) src/llamafactory/data/parser.py:93— parser.get_dataset_list has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
trainer_utils._create_galore_optimizer (cyclomatic 22) src/llamafactory/train/trainer_utils.py:200— trainer_utils._create_galore_optimizer has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
tuner.export_model (cyclomatic 22) src/llamafactory/train/tuner.py:176— tuner.export_model has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
format._to_hf_messages (cyclomatic 22) src/llamafactory/v1/core/rendering/format.py:38— format._to_hf_messages has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
FSDP2Engine.prepare_model (cyclomatic 22) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:244— FSDP2Engine.prepare_model has cyclomatic complexity 22 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Glm5NextTemplate._encode (cyclomatic 21) src/llamafactory/data/template.py:347— Glm5NextTemplate._encode has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
DataArguments.__post_init__ (cyclomatic 21) src/llamafactory/hparams/data_args.py:156— DataArguments.__post_init__ has cyclomatic complexity 21 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
collation._align_audio (cyclomatic 21) src/llamafactory/v1/core/utils/collation.py:142— collation._align_audio has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
FSDPTurboFSDP2Engine.prepare_model_ep (cyclomatic 21) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py:351— FSDPTurboFSDP2Engine.prepare_model_ep has cyclomatic complexity 21 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
AlpacaDatasetConverter.__call__ (cyclomatic 20) src/llamafactory/data/converter.py:86— AlpacaDatasetConverter.__call__ has cyclomatic complexity 20 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
trainer_utils._create_apollo_optimizer (cyclomatic 20) src/llamafactory/train/trainer_utils.py:288— trainer_utils._create_apollo_optimizer has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
launcher.launch (cyclomatic 20) REDACTED:34— launcher.launch has cyclomatic complexity 20 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
MiniCPMVPlugin.process_messages (cyclomatic 19) src/llamafactory/data/mm_plugin.py:1634— MiniCPMVPlugin.process_messages has cyclomatic complexity 19 (threshold 15). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
MiniCPMV4_6Plugin.process_messages (cyclomatic 19) src/llamafactory/data/mm_plugin.py:1892— MiniCPMV4_6Plugin.process_messages has cyclomatic complexity 19 (threshold 15). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
MegatronBridgeArguments.__post_init__ (cyclomatic 19) src/llamafactory/hparams/megatron_bridge_args.py:152— MegatronBridgeArguments.__post_init__ has cyclomatic complexity 19 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
ModelEngine._init_model (cyclomatic 19) src/llamafactory/v1/core/model_engine.py:136— ModelEngine._init_model has cyclomatic complexity 19 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
collation._align_grid_media (cyclomatic 19) src/llamafactory/v1/core/utils/collation.py:58— collation._align_grid_media has cyclomatic complexity 19 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
fsdpturbo.clip_grad_norm_ (cyclomatic 19) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py:129— fsdpturbo.clip_grad_norm_ has cyclomatic complexity 19 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
switcher.document.addEventListener("DOMContentLoaded")::hideOtherLanguageToc (cyclomatic 19) docs/_static/js/switcher.js:41— switcher.document.addEventListener("DOMContentLoaded")::hideOtherLanguageToc has cyclomatic complexity 19 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
InternVLPlugin._get_mm_inputs (cyclomatic 18) src/llamafactory/data/mm_plugin.py:1182— InternVLPlugin._get_mm_inputs has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
parser._check_extra_dependencies (cyclomatic 18) src/llamafactory/hparams/parser.py:272— parser._check_extra_dependencies has cyclomatic complexity 18 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
CustomSeq2SeqTrainer.__init__ (cyclomatic 18) src/llamafactory/train/sft/trainer.py:50— CustomSeq2SeqTrainer.__init__ has cyclomatic complexity 18 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Glm5NextPlugin._decode_video (cyclomatic 17) src/llamafactory/data/mm_plugin.py:2796— Glm5NextPlugin._decode_video has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
workflow.run_sft (cyclomatic 17) src/llamafactory/train/hyper_parallel/workflow.py:173— workflow.run_sft has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
BaseTrainer.fit (cyclomatic 17) src/llamafactory/v1/core/base_trainer.py:250— BaseTrainer.fit has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
Muon.step (cyclomatic 17) src/llamafactory/v1/plugins/trainer_plugins/optimizers/muon_optimizer.py:197— Muon.step has cyclomatic complexity 17 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
MMPluginMixin._validate_input (cyclomatic 16) src/llamafactory/data/mm_plugin.py:148— MMPluginMixin._validate_input has cyclomatic complexity 16 (threshold 15). To reduce it, name the conditions: bind each compound test to a well-named local or a small predicate function, so the body reads as a sequence of named decisions rather than a chain of operators.
MossVLPlugin.get_mm_inputs (cyclomatic 16) src/llamafactory/data/mm_plugin.py:665— MossVLPlugin.get_mm_inputs has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
embedding.resize_embedding_layer (cyclomatic 16) src/llamafactory/model/model_utils/embedding.py:262— embedding.resize_embedding_layer has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
_ChunkedLinearCrossEntropy.forward (cyclomatic 16) src/llamafactory/v1/plugins/model_plugins/chunk_loss.py:38— _ChunkedLinearCrossEntropy.forward has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
LigerKernel._apply (cyclomatic 16) src/llamafactory/v1/plugins/model_plugins/kernels/liger_kernel_ops.py:63— LigerKernel._apply has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
export.save_model (cyclomatic 16) src/llamafactory/webui/components/export.py:47— export.save_model has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Runner._initialize (cyclomatic 16) src/llamafactory/webui/runner.py:81— Runner._initialize has cyclomatic complexity 16 (threshold 15). To reduce it, split the body: these branches sit side by side rather than nested inside one another, so extracting each one on its own would leave a function per branch. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
Runner.monitor (cyclomatic 16) src/llamafactory/webui/runner.py:422— Runner.monitor has cyclomatic complexity 16 (threshold 15). To reduce it, separate the cases: extract each independent branch into its own named function, and where the body has guards that only reject input, fold those into early returns at the top.
parser.get_train_args (cognitive 137) src/llamafactory/hparams/parser.py:418— parser.get_train_args has cognitive complexity 137 (threshold 15). Drivers by points: if/else 65 (92 pts), boolean chains 44, ternaries 1 (nesting depth added 27). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
adapter._setup_lora_tuning (cognitive 101) src/llamafactory/model/adapter.py:147— adapter._setup_lora_tuning has cognitive complexity 101 (threshold 15). Drivers by points: if/else 37 (83 pts), boolean chains 8, loops 3 (7 pts), ternaries 1 (3 pts) (nesting depth added 52). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
Qwen2OmniPlugin.process_messages (cognitive 67) src/llamafactory/data/mm_plugin.py:3178— Qwen2OmniPlugin.process_messages has cognitive complexity 67 (threshold 15). Drivers by points: if/else 11 (28 pts), ternaries 5 (21 pts), loops 6 (16 pts), boolean chains 2 (nesting depth added 43). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
quantization.configure_quantization (cognitive 63) src/llamafactory/model/model_utils/quantization.py:86— quantization.configure_quantization has cognitive complexity 63 (threshold 15). Drivers by points: if/else 24 (56 pts), boolean chains 5, error handling 1 (2 pts) (nesting depth added 33). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
BaseTrainer.fit (cognitive 56) src/llamafactory/v1/core/base_trainer.py:250— BaseTrainer.fit has cognitive complexity 56 (threshold 15). Drivers by points: if/else 14 (42 pts), ternaries 2 (7 pts), loops 3 (6 pts), boolean chains 1 (nesting depth added 36). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
chat._process_request (cognitive 54) src/llamafactory/api/chat.py:73— chat._process_request has cognitive complexity 54 (threshold 15). Drivers by points: if/else 20 (38 pts), boolean chains 7, loops 2 (4 pts), ternaries 1 (3 pts), error handling 1 (2 pts) (nesting depth added 23). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
FSDP2Engine._load_weights_from_hf_checkpoint (cognitive 53) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:509— FSDP2Engine._load_weights_from_hf_checkpoint has cognitive complexity 53 (threshold 15). Drivers by points: if/else 18 (41 pts), loops 5 (12 pts) (nesting depth added 30). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
OpenAIDatasetConverter.__call__ (cognitive 45) src/llamafactory/data/converter.py:232— OpenAIDatasetConverter.__call__ has cognitive complexity 45 (threshold 15). Drivers by points: if/else 19 (28 pts), boolean chains 9, ternaries 5 (6 pts), loops 2 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
loader.load_model (cognitive 45) src/llamafactory/model/loader.py:138— loader.load_model has cognitive complexity 45 (threshold 15). Drivers by points: if/else 24 (38 pts), boolean chains 5, loops 1 (2 pts) (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MultiModalDataCollatorForSeq2Seq.__call__ (cognitive 44) src/llamafactory/data/collator.py:336— MultiModalDataCollatorForSeq2Seq.__call__ has cognitive complexity 44 (threshold 15). Drivers by points: if/else 19 (27 pts), boolean chains 10, loops 3 (5 pts), ternaries 1 (2 pts) (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
PackedSupervisedDatasetProcessor.preprocess_dataset (cognitive 44) src/llamafactory/data/processor/supervised.py:147— PackedSupervisedDatasetProcessor.preprocess_dataset has cognitive complexity 44 (threshold 15). Drivers by points: if/else 13 (27 pts), boolean chains 13, loops 3 (4 pts) (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
format._to_hf_messages (cognitive 44) src/llamafactory/v1/core/rendering/format.py:38— format._to_hf_messages has cognitive complexity 44 (threshold 15). Drivers by points: if/else 8 (25 pts), error handling 2 (10 pts), loops 3 (7 pts), boolean chains 2 (nesting depth added 29). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Muon.step (cognitive 42) src/llamafactory/v1/plugins/trainer_plugins/optimizers/muon_optimizer.py:197— Muon.step has cognitive complexity 42 (threshold 15). Drivers by points: if/else 13 (31 pts), ternaries 2 (6 pts), loops 3 (5 pts) (nesting depth added 24). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
FSDP2Engine.prepare_model (cognitive 41) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:244— FSDP2Engine.prepare_model has cognitive complexity 41 (threshold 15). Drivers by points: if/else 15 (28 pts), ternaries 3 (7 pts), loops 3 (5 pts), boolean chains 1 (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
trainer_utils._create_galore_optimizer (cognitive 40) src/llamafactory/train/trainer_utils.py:200— trainer_utils._create_galore_optimizer has cognitive complexity 40 (threshold 15). Drivers by points: if/else 13 (24 pts), loops 7 (13 pts), boolean chains 3 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
trainer_utils._create_apollo_optimizer (cognitive 40) src/llamafactory/train/trainer_utils.py:288— trainer_utils._create_apollo_optimizer has cognitive complexity 40 (threshold 15). Drivers by points: if/else 13 (24 pts), loops 7 (13 pts), boolean chains 3 (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
adapter._setup_freeze_tuning (cognitive 39) src/llamafactory/model/adapter.py:57— adapter._setup_freeze_tuning has cognitive complexity 39 (threshold 15). Drivers by points: if/else 16 (25 pts), loops 5 (7 pts), boolean chains 4, ternaries 1 (3 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
FSDPTurboFSDP2Engine.prepare_model_ep (cognitive 39) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py:351— FSDPTurboFSDP2Engine.prepare_model_ep has cognitive complexity 39 (threshold 15). Drivers by points: if/else 15 (30 pts), loops 3 (7 pts), boolean chains 2 (nesting depth added 19). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
HuggingfaceEngine._process_args (cognitive 38) src/llamafactory/chat/hf_engine.py:73— HuggingfaceEngine._process_args has cognitive complexity 38 (threshold 15). Drivers by points: if/else 19 (26 pts), ternaries 7, boolean chains 4, loops 1 (nesting depth added 7). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
Glm5NextTemplate._encode (cognitive 38) src/llamafactory/data/template.py:347— Glm5NextTemplate._encode has cognitive complexity 38 (threshold 15). Drivers by points: if/else 14 (31 pts), boolean chains 4, ternaries 1 (2 pts), loops 1 (nesting depth added 18). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
peft.get_freeze_model (cognitive 38) src/llamafactory/v1/plugins/model_plugins/peft.py:207— peft.get_freeze_model has cognitive complexity 38 (threshold 15). Drivers by points: if/else 17 (25 pts), loops 6 (11 pts), boolean chains 2 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser.get_dataset_list (cognitive 34) src/llamafactory/data/parser.py:93— parser.get_dataset_list has cognitive complexity 34 (threshold 15). Drivers by points: if/else 12 (20 pts), ternaries 2 (6 pts), boolean chains 5, error handling 1 (2 pts), loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
attention.configure_attn_implementation (cognitive 34) src/llamafactory/model/model_utils/attention.py:32— attention.configure_attn_implementation has cognitive complexity 34 (threshold 15). Drivers by points: if/else 19 (32 pts), boolean chains 2 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Runner._parse_train_args (cognitive 33) src/llamafactory/webui/runner.py:133— Runner._parse_train_args has cognitive complexity 33 (threshold 15). Drivers by points: if/else 17 (20 pts), boolean chains 7, ternaries 4 (6 pts) (nesting depth added 5). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
MultiModalDataCollatorForSeq2Seq._compute_rope_position_ids_with_packing (cognitive 32) src/llamafactory/data/collator.py:206— MultiModalDataCollatorForSeq2Seq._compute_rope_position_ids_with_packing has cognitive complexity 32 (threshold 15). Drivers by points: if/else 8 (10 pts), ternaries 6 (10 pts), boolean chains 8, loops 2 (4 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
GLM4VPlugin.process_messages (cognitive 32) src/llamafactory/data/mm_plugin.py:3026— GLM4VPlugin.process_messages has cognitive complexity 32 (threshold 15). Drivers by points: ternaries 4 (12 pts), if/else 6 (10 pts), loops 5 (10 pts) (nesting depth added 17). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
VllmEngine._generate (cognitive 31) src/llamafactory/chat/vllm_engine.py:111— VllmEngine._generate has cognitive complexity 31 (threshold 15). Drivers by points: if/else 13 (14 pts), boolean chains 10, ternaries 6 (7 pts) (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
patcher.patch_config (cognitive 31) src/llamafactory/model/patcher.py:365— patcher.patch_config has cognitive complexity 31 (threshold 15). Drivers by points: if/else 16 (19 pts), boolean chains 10, loops 1 (2 pts) (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
MiniCPMVPlugin.process_messages (cognitive 30) src/llamafactory/data/mm_plugin.py:1634— MiniCPMVPlugin.process_messages has cognitive complexity 30 (threshold 15). Drivers by points: loops 8 (17 pts), if/else 7, boolean chains 3, ternaries 1 (3 pts) (nesting depth added 11). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
Glm5NextPlugin._decode_video (cognitive 30) src/llamafactory/data/mm_plugin.py:2796— Glm5NextPlugin._decode_video has cognitive complexity 30 (threshold 15). Drivers by points: if/else 12 (23 pts), loops 2 (3 pts), boolean chains 2, ternaries 1 (2 pts) (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
tuner._training_function (cognitive 30) src/llamafactory/train/tuner.py:69— tuner._training_function has cognitive complexity 30 (threshold 15). Drivers by points: if/else 18 (25 pts), boolean chains 4, error handling 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
tuner.export_model (cognitive 30) src/llamafactory/train/tuner.py:176— tuner.export_model has cognitive complexity 30 (threshold 15). Drivers by points: if/else 19 (26 pts), boolean chains 2, error handling 2 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
collation._align_audio (cognitive 30) src/llamafactory/v1/core/utils/collation.py:142— collation._align_audio has cognitive complexity 30 (threshold 15). Drivers by points: if/else 14 (22 pts), loops 4 (5 pts), ternaries 2, boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MossVLPlugin.get_mm_inputs (cognitive 29) src/llamafactory/data/mm_plugin.py:665— MossVLPlugin.get_mm_inputs has cognitive complexity 29 (threshold 15). Drivers by points: if/else 12 (23 pts), boolean chains 3, loops 2 (3 pts) (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MiniCPMV4_6Plugin.process_messages (cognitive 29) src/llamafactory/data/mm_plugin.py:1892— MiniCPMV4_6Plugin.process_messages has cognitive complexity 29 (threshold 15). Drivers by points: loops 8 (17 pts), if/else 7 (9 pts), boolean chains 3 (nesting depth added 11). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
workflow.run_sft (cognitive 29) src/llamafactory/train/sft/workflow.py:41— workflow.run_sft has cognitive complexity 29 (threshold 15). Drivers by points: if/else 17 (24 pts), ternaries 3, boolean chains 2 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
FSDP2Engine.shard_model (cognitive 29) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:386— FSDP2Engine.shard_model has cognitive complexity 29 (threshold 15). Drivers by points: if/else 10 (20 pts), loops 2 (7 pts), ternaries 1 (2 pts) (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Runner.monitor (cognitive 29) src/llamafactory/webui/runner.py:422— Runner.monitor has cognitive complexity 29 (threshold 15). Drivers by points: if/else 11 (20 pts), ternaries 5, error handling 1 (2 pts), boolean chains 1, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Qwen2VLPlugin._regularize_videos (cognitive 28) src/llamafactory/data/mm_plugin.py:2279— Qwen2VLPlugin._regularize_videos has cognitive complexity 28 (threshold 15). Drivers by points: if/else 8 (20 pts), loops 3 (7 pts), boolean chains 1 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
FinetuningArguments.__post_init__ (cognitive 28) src/llamafactory/hparams/finetuning_args.py:602— FinetuningArguments.__post_init__ has cognitive complexity 28 (threshold 15). Drivers by points: if/else 13 (17 pts), boolean chains 11 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
escape._escape_special_in_messages (cognitive 28) src/llamafactory/v1/core/rendering/escape.py:62— escape._escape_special_in_messages has cognitive complexity 28 (threshold 15). Drivers by points: if/else 6 (15 pts), ternaries 1 (6 pts), error handling 1 (4 pts), loops 2 (3 pts) (nesting depth added 18). To reduce it, flatten the nesting: this score is depth rather than breadth — most of its points come from checks stacked inside one another, so the work sits several levels in. Invert each enclosing check into an early exit (a return, or the language's equivalent) so the happy path stays at one level, and where a level cannot be exited early, lift the block it encloses into its own named function.
Renderer.process_samples (cognitive 28) src/llamafactory/v1/core/rendering/rendering.py:262— Renderer.process_samples has cognitive complexity 28 (threshold 15). Drivers by points: if/else 7 (20 pts), loops 3 (6 pts), boolean chains 2 (nesting depth added 16). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SGLangEngine._generate (cognitive 27) src/llamafactory/chat/sglang_engine.py:140— SGLangEngine._generate has cognitive complexity 27 (threshold 15). Drivers by points: if/else 10 (11 pts), boolean chains 9, ternaries 6 (7 pts) (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
loader._load_single_dataset (cognitive 27) src/llamafactory/data/loader.py:51— loader._load_single_dataset has cognitive complexity 27 (threshold 15). Drivers by points: if/else 13 (19 pts), boolean chains 5, loops 1 (3 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ModelEngine._init_model (cognitive 27) src/llamafactory/v1/core/model_engine.py:136— ModelEngine._init_model has cognitive complexity 27 (threshold 15). Drivers by points: if/else 17 (21 pts), boolean chains 2, error handling 1 (2 pts), ternaries 2 (nesting depth added 5). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
DatasetConverter._find_medias (cognitive 26) src/llamafactory/data/converter.py:43— DatasetConverter._find_medias has cognitive complexity 26 (threshold 15). Drivers by points: if/else 8 (16 pts), loops 3 (10 pts) (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SharegptDatasetConverter.__call__ (cognitive 26) src/llamafactory/data/converter.py:136— SharegptDatasetConverter.__call__ has cognitive complexity 26 (threshold 15). Drivers by points: if/else 9 (12 pts), boolean chains 7, ternaries 5 (6 pts), loops 1 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
data_utils.split_dataset (cognitive 26) src/llamafactory/data/data_utils.py:85— data_utils.split_dataset has cognitive complexity 26 (threshold 15). Drivers by points: if/else 11 (18 pts), ternaries 1 (4 pts), loops 1 (3 pts), boolean chains 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MMPluginMixin._regularize_videos (cognitive 26) src/llamafactory/data/mm_plugin.py:279— MMPluginMixin._regularize_videos has cognitive complexity 26 (threshold 15). Drivers by points: if/else 7 (18 pts), loops 3 (7 pts), boolean chains 1 (nesting depth added 15). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
moe.add_z3_leaf_module (cognitive 26) src/llamafactory/model/model_utils/moe.py:43— moe.add_z3_leaf_module has cognitive complexity 26 (threshold 15). Drivers by points: if/else 24, boolean chains 2. To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
patcher.patch_model (cognitive 26) src/llamafactory/model/patcher.py:440— patcher.patch_model has cognitive complexity 26 (threshold 15). Drivers by points: if/else 10 (15 pts), boolean chains 10, error handling 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
workflow.run_dpo (cognitive 26) src/llamafactory/train/dpo/workflow.py:35— workflow.run_dpo has cognitive complexity 26 (threshold 15). Drivers by points: if/else 12 (20 pts), loops 1 (3 pts), boolean chains 2, ternaries 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
cli_sampler.run_chat (cognitive 25) src/llamafactory/v1/samplers/cli_sampler.py:75— cli_sampler.run_chat has cognitive complexity 25 (threshold 15). Drivers by points: if/else 6 (11 pts), error handling 3 (9 pts), loops 2 (5 pts) (nesting depth added 14). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
fsdpturbo.clip_grad_norm_ (cognitive 24) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py:129— fsdpturbo.clip_grad_norm_ has cognitive complexity 24 (threshold 15). Drivers by points: if/else 9 (13 pts), boolean chains 4, ternaries 4, loops 2 (3 pts) (nesting depth added 5). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
InternVLPlugin._get_mm_inputs (cognitive 23) src/llamafactory/data/mm_plugin.py:1182— InternVLPlugin._get_mm_inputs has cognitive complexity 23 (threshold 15). Drivers by points: if/else 10, ternaries 2 (6 pts), loops 2 (4 pts), boolean chains 3 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
DataArguments.__post_init__ (cognitive 23) src/llamafactory/hparams/data_args.py:156— DataArguments.__post_init__ has cognitive complexity 23 (threshold 15). Drivers by points: if/else 13 (16 pts), boolean chains 7 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
workflow.run_sft (cognitive 23) src/llamafactory/train/hyper_parallel/workflow.py:173— workflow.run_sft has cognitive complexity 23 (threshold 15). Drivers by points: if/else 13 (19 pts), ternaries 3, boolean chains 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
collation._align_grid_media (cognitive 23) src/llamafactory/v1/core/utils/collation.py:58— collation._align_grid_media has cognitive complexity 23 (threshold 15). Drivers by points: if/else 13 (17 pts), boolean chains 2, loops 2, ternaries 2 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
Gemma4ToolUtils.tool_formatter (cognitive 22) src/llamafactory/data/tool_utils.py:246— Gemma4ToolUtils.tool_formatter has cognitive complexity 22 (threshold 15). Drivers by points: if/else 7 (19 pts), ternaries 1 (2 pts), loops 1 (nesting depth added 13). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CustomKTOTrainer.__init__ (cognitive 22) src/llamafactory/train/kto/trainer.py:44— CustomKTOTrainer.__init__ has cognitive complexity 22 (threshold 15). Drivers by points: if/else 14 (20 pts), boolean chains 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CustomSeq2SeqTrainer.__init__ (cognitive 22) src/llamafactory/train/sft/trainer.py:50— CustomSeq2SeqTrainer.__init__ has cognitive complexity 22 (threshold 15). Drivers by points: if/else 14 (20 pts), boolean chains 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
batching._pack_padding_free_samples (cognitive 22) src/llamafactory/v1/plugins/trainer_plugins/batching.py:123— batching._pack_padding_free_samples has cognitive complexity 22 (threshold 15). Drivers by points: if/else 6 (16 pts), loops 2 (3 pts), boolean chains 2, ternaries 1 (nesting depth added 11). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
AlpacaDatasetConverter.__call__ (cognitive 21) src/llamafactory/data/converter.py:86— AlpacaDatasetConverter.__call__ has cognitive complexity 21 (threshold 15). Drivers by points: if/else 7 (8 pts), boolean chains 6, ternaries 5, loops 1 (2 pts) (nesting depth added 2). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
LlavaNextVideoPlugin.process_messages (cognitive 21) src/llamafactory/data/mm_plugin.py:1507— LlavaNextVideoPlugin.process_messages has cognitive complexity 21 (threshold 15). Drivers by points: if/else 8 (15 pts), loops 4 (6 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
template.get_template_and_fix_tokenizer (cognitive 21) src/llamafactory/data/template.py:875— template.get_template_and_fix_tokenizer has cognitive complexity 21 (threshold 15). Drivers by points: if/else 11 (14 pts), ternaries 2 (5 pts), boolean chains 2 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
embedding.resize_embedding_layer (cognitive 21) src/llamafactory/model/model_utils/embedding.py:262— embedding.resize_embedding_layer has cognitive complexity 21 (threshold 15). Drivers by points: if/else 12 (16 pts), boolean chains 5 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
workflow.run_kto (cognitive 21) src/llamafactory/train/kto/workflow.py:35— workflow.run_kto has cognitive complexity 21 (threshold 15). Drivers by points: if/else 9 (15 pts), loops 1 (3 pts), boolean chains 2, ternaries 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CustomPPOTrainer.ppo_train (cognitive 21) src/llamafactory/train/ppo/trainer.py:200— CustomPPOTrainer.ppo_train has cognitive complexity 21 (threshold 15). Drivers by points: if/else 7 (11 pts), error handling 2 (5 pts), loops 2 (3 pts), boolean chains 2 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
_ChunkedLinearCrossEntropy.forward (cognitive 21) src/llamafactory/v1/plugins/model_plugins/chunk_loss.py:38— _ChunkedLinearCrossEntropy.forward has cognitive complexity 21 (threshold 15). Drivers by points: ternaries 8 (10 pts), if/else 4 (8 pts), boolean chains 2, loops 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LigerKernel._apply (cognitive 21) src/llamafactory/v1/plugins/model_plugins/kernels/liger_kernel_ops.py:63— LigerKernel._apply has cognitive complexity 21 (threshold 15). Drivers by points: if/else 11 (15 pts), boolean chains 4, loops 1 (2 pts) (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
switcher.document.addEventListener("DOMContentLoaded")::hideOtherLanguageToc (cognitive 21) docs/_static/js/switcher.js:41— switcher.document.addEventListener("DOMContentLoaded")::hideOtherLanguageToc has cognitive complexity 21 (threshold 15). Drivers by points: if/else 7 (12 pts), boolean chains 8, loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Qwen3VLPlugin.process_messages (cognitive 20) src/llamafactory/data/mm_plugin.py:2707— Qwen3VLPlugin.process_messages has cognitive complexity 20 (threshold 15). Drivers by points: loops 4 (9 pts), if/else 5 (8 pts), ternaries 1 (3 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Template._encode (cognitive 20) src/llamafactory/data/template.py:132— Template._encode has cognitive complexity 20 (threshold 15). Drivers by points: if/else 5 (12 pts), ternaries 1 (4 pts), boolean chains 3, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (MossVLTemplate._encode) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
MossVLTemplate._encode (cognitive 20) src/llamafactory/data/template.py:412— MossVLTemplate._encode has cognitive complexity 20 (threshold 15). Drivers by points: if/else 5 (12 pts), ternaries 1 (4 pts), boolean chains 3, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (Template._encode) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
MegatronBridgeArguments.__post_init__ (cognitive 20) src/llamafactory/hparams/megatron_bridge_args.py:152— MegatronBridgeArguments.__post_init__ has cognitive complexity 20 (threshold 15). Drivers by points: if/else 13 (14 pts), boolean chains 6 (nesting depth added 1). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
CustomDPOTrainer.__init__ (cognitive 20) src/llamafactory/train/dpo/trainer.py:45— CustomDPOTrainer.__init__ has cognitive complexity 20 (threshold 15). Drivers by points: if/else 13 (19 pts), boolean chains 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CustomPPOTrainer.__init__ (cognitive 20) src/llamafactory/train/ppo/trainer.py:67— CustomPPOTrainer.__init__ has cognitive complexity 20 (threshold 15). Drivers by points: if/else 12 (16 pts), ternaries 2, boolean chains 1, error handling 1 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
checkpoint._load_standard_training_states (cognitive 20) src/llamafactory/v1/core/utils/checkpoint.py:185— checkpoint._load_standard_training_states has cognitive complexity 20 (threshold 15). Drivers by points: if/else 9 (14 pts), loops 2 (5 pts), ternaries 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
fsdp2.get_transformer_layer_cls (cognitive 20) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:103— fsdp2.get_transformer_layer_cls has cognitive complexity 20 (threshold 15). Drivers by points: if/else 6 (13 pts), loops 3 (5 pts), boolean chains 2 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MossVLPlugin.post_process_mossvl_inputs (cognitive 19) src/llamafactory/data/mm_plugin.py:776— MossVLPlugin.post_process_mossvl_inputs has cognitive complexity 19 (threshold 15). Drivers by points: if/else 4 (13 pts), loops 2 (5 pts), boolean chains 1 (nesting depth added 12). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Qwen38ReasoningTemplate._encode (cognitive 19) src/llamafactory/data/template.py:623— Qwen38ReasoningTemplate._encode has cognitive complexity 19 (threshold 15). Drivers by points: if/else 7 (17 pts), boolean chains 1, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Xing4ToolUtils.tool_extractor (cognitive 19) src/llamafactory/data/tool_utils.py:897— Xing4ToolUtils.tool_extractor has cognitive complexity 19 (threshold 15). Drivers by points: if/else 6 (12 pts), error handling 1 (3 pts), loops 2 (3 pts), boolean chains 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
parser._check_extra_dependencies (cognitive 19) src/llamafactory/hparams/parser.py:272— parser._check_extra_dependencies has cognitive complexity 19 (threshold 15). Drivers by points: if/else 16 (19 pts) (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
FlashLinearAttentionKernel._apply (cognitive 19) src/llamafactory/v1/plugins/model_plugins/kernels/ops/linear_attention/fla.py:61— FlashLinearAttentionKernel._apply has cognitive complexity 19 (threshold 15). Drivers by points: if/else 8 (11 pts), ternaries 2 (4 pts), boolean chains 3, loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MossVLPlugin._get_media_order_from_ids (cognitive 18) src/llamafactory/data/mm_plugin.py:558— MossVLPlugin._get_media_order_from_ids has cognitive complexity 18 (threshold 15). Drivers by points: if/else 8 (15 pts), boolean chains 2, loops 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Gemma4Plugin._regularize_videos (cognitive 18) src/llamafactory/data/mm_plugin.py:973— Gemma4Plugin._regularize_videos has cognitive complexity 18 (threshold 15). Drivers by points: if/else 6 (14 pts), loops 2 (4 pts) (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
MiniCPMVPlugin._get_mm_inputs (cognitive 18) src/llamafactory/data/mm_plugin.py:1562— MiniCPMVPlugin._get_mm_inputs has cognitive complexity 18 (threshold 15). Drivers by points: if/else 7 (10 pts), loops 2 (6 pts), ternaries 1 (2 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SupervisedDatasetProcessor._encode_data_example (cognitive 18) src/llamafactory/data/processor/supervised.py:52— SupervisedDatasetProcessor._encode_data_example has cognitive complexity 18 (threshold 15). Drivers by points: if/else 9 (13 pts), boolean chains 3, loops 1, ternaries 1 (nesting depth added 4). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Template._convert_slots_to_jinja (cognitive 18) src/llamafactory/data/template.py:229— Template._convert_slots_to_jinja has cognitive complexity 18 (threshold 15). Drivers by points: if/else 5 (15 pts), boolean chains 2, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (Template._convert_slots_to_ollama) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
Template._convert_slots_to_ollama (cognitive 18) src/llamafactory/data/template.py:288— Template._convert_slots_to_ollama has cognitive complexity 18 (threshold 15). Drivers by points: if/else 5 (15 pts), boolean chains 2, loops 1 (nesting depth added 10). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body. This shape REPEATS in the file: one other method here (Template._convert_slots_to_jinja) has the same decision points, in the same order, at the same nesting depths — so this is one pattern written twice rather than two separate problems. Splitting this body alone leaves the other exactly as it is. Where these are variations on one operation, the change that clears both is the shared one: lift the common shape into a single routine the variants call, parameterised by whatever genuinely differs between them, and keep in each method only the part that is not shared.
dataset_export._example_to_record (cognitive 18) src/llamafactory/train/megatron_bridge/dataset_export.py:210— dataset_export._example_to_record has cognitive complexity 18 (threshold 15). Drivers by points: if/else 7 (10 pts), loops 4 (6 pts), boolean chains 2 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CustomPPOTrainer.batched_forward_pass (cognitive 18) src/llamafactory/train/ppo/trainer.py:422— CustomPPOTrainer.batched_forward_pass has cognitive complexity 18 (threshold 15). Drivers by points: if/else 6 (14 pts), loops 2 (3 pts), ternaries 1 (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
batching.default_collate_fn (cognitive 18) src/llamafactory/v1/core/utils/batching.py:124— batching.default_collate_fn has cognitive complexity 18 (threshold 15). Drivers by points: loops 4 (10 pts), if/else 3 (6 pts), boolean chains 2 (nesting depth added 9). To reduce it, break up the iteration: give each loop body a named function, and split a multi-phase loop into one function per phase so no single body carries the whole pipeline.
data_utils.get_dataset_module (cognitive 17) src/llamafactory/data/data_utils.py:134— data_utils.get_dataset_module has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (14 pts), loops 1 (3 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Gemma4Plugin.process_messages (cognitive 17) src/llamafactory/data/mm_plugin.py:1077— Gemma4Plugin.process_messages has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (10 pts), loops 4 (7 pts) (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
VideoLlavaPlugin.process_messages (cognitive 17) src/llamafactory/data/mm_plugin.py:3302— VideoLlavaPlugin.process_messages has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (11 pts), loops 3 (5 pts), boolean chains 1 (nesting depth added 7). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
LFM2ToolUtils.tool_extractor (cognitive 17) src/llamafactory/data/tool_utils.py:1052— LFM2ToolUtils.tool_extractor has cognitive complexity 17 (threshold 15). Drivers by points: if/else 7 (9 pts), error handling 2 (4 pts), loops 2 (3 pts), ternaries 1 (nesting depth added 5). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
checkpointing.prepare_model_for_training (cognitive 17) src/llamafactory/model/model_utils/checkpointing.py:163— checkpointing.prepare_model_for_training has cognitive complexity 17 (threshold 15). Drivers by points: if/else 8 (12 pts), boolean chains 3, loops 1 (2 pts) (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
patcher.patch_qwen3_5_forward_npu (cognitive 17) src/llamafactory/model/patcher.py:88— patcher.patch_qwen3_5_forward_npu has cognitive complexity 17 (threshold 15). Drivers by points: if/else 4 (8 pts), error handling 3 (5 pts), loops 2 (4 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
CustomKTOTrainer.log (cognitive 17) src/llamafactory/train/kto/trainer.py:278— CustomKTOTrainer.log has cognitive complexity 17 (threshold 15). Drivers by points: loops 5 (8 pts), if/else 4 (6 pts), ternaries 2, boolean chains 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
BaseTrainer.__init__ (cognitive 17) src/llamafactory/v1/core/base_trainer.py:57— BaseTrainer.__init__ has cognitive complexity 17 (threshold 15). Drivers by points: if/else 11 (13 pts), boolean chains 2, loops 1, ternaries 1 (nesting depth added 2). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
rendering._render_messages (cognitive 17) src/llamafactory/v1/core/rendering/rendering.py:46— rendering._render_messages has cognitive complexity 17 (threshold 15). Drivers by points: if/else 8 (9 pts), ternaries 2 (3 pts), boolean chains 2, error handling 1 (2 pts), loops 1 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
collation.pad_and_truncate (cognitive 17) src/llamafactory/v1/core/utils/collation.py:250— collation.pad_and_truncate has cognitive complexity 17 (threshold 15). Drivers by points: if/else 6 (13 pts), loops 2 (3 pts), boolean chains 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
peft.merge_and_export_model (cognitive 17) src/llamafactory/v1/plugins/model_plugins/peft.py:301— peft.merge_and_export_model has cognitive complexity 17 (threshold 15). Drivers by points: if/else 11 (14 pts), error handling 1 (2 pts), boolean chains 1 (nesting depth added 4). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition, and where an else follows a branch that already returns, drop the trailing else and let the rest of the body continue at one level.
FSDP2Engine._copy_weights (cognitive 17) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:712— FSDP2Engine._copy_weights has cognitive complexity 17 (threshold 15). Drivers by points: if/else 8 (15 pts), loops 1 (2 pts) (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Runner._initialize (cognitive 17) src/llamafactory/webui/runner.py:81— Runner._initialize has cognitive complexity 17 (threshold 15). Drivers by points: if/else 9 (11 pts), boolean chains 3, error handling 1 (2 pts), ternaries 1 (nesting depth added 3). To reduce it, split the body: most of this score is breadth rather than depth — checks laid out side by side rather than stacked — so group the statements between the checks into named steps and move each step into its own function. Some of it IS depth: where a check sits inside another whose only job is to reach it, merge the two into one condition.
MultiModalDataCollatorForSeq2Seq._compute_rope_position_ids (cognitive 16) src/llamafactory/data/collator.py:162— MultiModalDataCollatorForSeq2Seq._compute_rope_position_ids has cognitive complexity 16 (threshold 15). Drivers by points: if/else 9 (15 pts), boolean chains 1 (nesting depth added 6). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
SFTDataCollatorWith4DAttentionMask.__call__ (cognitive 16) src/llamafactory/data/collator.py:542— SFTDataCollatorWith4DAttentionMask.__call__ has cognitive complexity 16 (threshold 15). Drivers by points: if/else 7 (12 pts), boolean chains 3, loops 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
ReasoningTemplate.encode_multiturn (cognitive 16) src/llamafactory/data/template.py:556— ReasoningTemplate.encode_multiturn has cognitive complexity 16 (threshold 15). Drivers by points: if/else 7 (10 pts), loops 3 (5 pts), boolean chains 1 (nesting depth added 5). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
longlora.llama_sdpa_attention_forward (cognitive 16) src/llamafactory/model/model_utils/longlora.py:249— longlora.llama_sdpa_attention_forward has cognitive complexity 16 (threshold 15). Drivers by points: if/else 9 (10 pts), boolean chains 4, ternaries 2 (nesting depth added 1). To reduce it, split the body: this score is breadth rather than depth — many checks laid out side by side rather than nested inside one another, so inverting conditions into early returns has nothing left to flatten. Group the statements between the checks into named steps and move each step into its own function, so the body reads as a short sequence of named stages.
PairwiseTrainer._save (cognitive 16) src/llamafactory/train/rm/trainer.py:113— PairwiseTrainer._save has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (8 pts), loops 3 (8 pts) (nesting depth added 9). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
converter.sharegpt_converter (cognitive 16) src/llamafactory/v1/plugins/data_plugins/converter.py:173— converter.sharegpt_converter has cognitive complexity 16 (threshold 15). Drivers by points: if/else 4 (7 pts), error handling 2 (5 pts), ternaries 1 (3 pts), loops 1 (nesting depth added 8). To reduce it, split the body into named stages: move each independent step or branch into its own named function so the body reads as a short sequence of named calls rather than one long body.
Change coupling clique: cal_lr.py, cal_ppl.py, length_cdf.py scripts/stat_utils/cal_lr.py— 3 files — `scripts/stat_utils/cal_lr.py`, `scripts/stat_utils/cal_ppl.py`, `scripts/stat_utils/length_cdf.py` — all change together with no explicit dependency: a fully-connected co-change clique, not 3 separate couplings. They share one concern (thin parallel siblings over a common abstraction), so extract the shared part into ONE unit and the whole clique's coupling clears at once — you do not need to break each pair individually.
D4 · Code Duplication· Near-duplicate member family (5 members, 17 shared lines) · ×1
Near-duplicate member family (5 members, 17 shared lines) src/llamafactory/data/mm_plugin.py:1018— src/llamafactory/data/mm_plugin.py:1018-1074 | src/llamafactory/data/mm_plugin.py:2528-2552 | src/llamafactory/data/mm_plugin.py:2661-2704 | src/llamafactory/data/mm_plugin.py:2997-3023 | src/llamafactory/data/mm_plugin.py:3131-3175 — These 5 members are variants of one another: a block of 17 lines reported below appears in every one of them, and the pairwise near-duplicate rows they would otherwise produce are collapsed into this row. Read them as one construct written 5 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 5 times.
D4 · Code Duplication· Near-duplicate member family (3 members, 43 shared lines) · ×1
Near-duplicate member family (3 members, 43 shared lines) src/llamafactory/model/model_utils/longlora.py:67— src/llamafactory/model/model_utils/longlora.py:67-136 | src/llamafactory/model/model_utils/longlora.py:153-244 | src/llamafactory/model/model_utils/longlora.py:260-349 — These 3 members are variants of one another: a block of 43 lines reported below appears in every one of them, and the pairwise near-duplicate rows they would otherwise produce are collapsed into this row. Read them as one construct written 3 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 3 times.
Near-duplicate member pair (65 shared lines) src/llamafactory/train/hyper_parallel/workflow.py:181— src/llamafactory/train/hyper_parallel/workflow.py:181-288 | src/llamafactory/train/sft/workflow.py:49-160 — These two members are variants of one another: 65 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
Near-duplicate member pair (36 shared lines) src/llamafactory/train/mca/workflow.py:170— src/llamafactory/train/mca/workflow.py:170-212 | src/llamafactory/train/mca/workflow.py:224-278 — These two members are variants of one another: 36 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
Near-duplicate member pair (29 shared lines) src/llamafactory/chat/sglang_engine.py:150— src/llamafactory/chat/sglang_engine.py:150-232 | src/llamafactory/chat/vllm_engine.py:121-218 — These two members are variants of one another: 29 of their lines are already reported as duplicated blocks below, spread through both bodies rather than gathered into one. Read them as a single construct written twice. The repair is at the members' grain — factor the shared pipeline into one implementation the two call with their differences as parameters or as an injected step, or, where the difference is systematic (sync against async, one transport against another), generate one from the other. Extracting the individual blocks below is not the same fix: it leaves the two bodies in place and the next edit still has to be made twice.
D4 · Code Duplication· Edited copy of a member (13 corresponding lines) · ×1
Edited copy of a member (13 corresponding lines) src/llamafactory/data/processor/feedback.py:42— src/llamafactory/data/processor/feedback.py:42-83 | src/llamafactory/data/processor/unsupervised.py:41-57 — These two members are one piece of code written twice and then edited apart: 13 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Members sharing a duplicated core (5 members, 50+ identical tokens) · ×1
Members sharing a duplicated core (5 members, 50+ identical tokens) src/llamafactory/data/processor/feedback.py:87— src/llamafactory/data/processor/feedback.py:87-122 | src/llamafactory/data/processor/pairwise.py:73-100 | src/llamafactory/data/processor/supervised.py:111-135 | src/llamafactory/data/processor/supervised.py:151-252 | src/llamafactory/data/processor/unsupervised.py:61-85 — These 5 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 5 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 5 times.
D4 · Code Duplication· Members sharing a duplicated core (4 members, 50+ identical tokens) · ×1
Members sharing a duplicated core (4 members, 50+ identical tokens) src/llamafactory/data/template.py:139— src/llamafactory/data/template.py:139-176 | src/llamafactory/data/template.py:419-450 | src/llamafactory/data/template.py:465-490 | src/llamafactory/data/template.py:630-663 — These 4 members share a duplicated core: a run of at least 50 identical tokens appears in every one of them. That run is NOT broken out as duplicated-block rows below — it is what admitted this row, and the blocks below cover only the part of it that clears the block floor, so they understate the correspondence. Read the members as one construct written 4 times. The repair is at the members' grain — factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Extracting the individual blocks below is not the same fix: it leaves every body in place and the next edit still has to be made 4 times.
D4 · Code Duplication· Edited copy of a member (77 corresponding lines) · ×1
Edited copy of a member (77 corresponding lines) src/llamafactory/train/trainer_utils.py:205— src/llamafactory/train/trainer_utils.py:205-285 | src/llamafactory/train/trainer_utils.py:293-369 — These two members are one piece of code written twice and then edited apart: 77 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (72 corresponding lines) · ×1
Edited copy of a member (72 corresponding lines) src/llamafactory/data/mm_plugin.py:1642— src/llamafactory/data/mm_plugin.py:1642-1722 | src/llamafactory/data/mm_plugin.py:1900-1971 — These two members are one piece of code written twice and then edited apart: 72 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (68 corresponding lines) · ×1
Edited copy of a member (68 corresponding lines) src/llamafactory/train/dpo/trainer.py:54— src/llamafactory/train/dpo/trainer.py:54-123 | src/llamafactory/train/kto/trainer.py:53-120 — These two members are one piece of code written twice and then edited apart: 68 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (60 corresponding lines) · ×1
Edited copy of a member (60 corresponding lines) src/llamafactory/train/dpo/workflow.py:42— src/llamafactory/train/dpo/workflow.py:42-111 | src/llamafactory/train/kto/workflow.py:42-101 — These two members are one piece of code written twice and then edited apart: 60 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (35 corresponding lines) · ×1
Edited copy of a member (35 corresponding lines) src/llamafactory/data/mm_plugin.py:974— src/llamafactory/data/mm_plugin.py:974-1008 | src/llamafactory/data/mm_plugin.py:2280-2325 — These two members are one piece of code written twice and then edited apart: 35 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (38 corresponding lines) · ×1
Edited copy of a member (38 corresponding lines) src/llamafactory/data/mm_plugin.py:835— src/llamafactory/data/mm_plugin.py:835-872 | src/llamafactory/data/mm_plugin.py:2563-2603 — These two members are one piece of code written twice and then edited apart: 38 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (44 corresponding lines) · ×1
Edited copy of a member (44 corresponding lines) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:713— src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:713-757 | src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py:306-349 — These two members are one piece of code written twice and then edited apart: 44 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (58 corresponding lines) · ×1
Edited copy of a member (58 corresponding lines) src/llamafactory/v1/plugins/data_plugins/converter.py:174— src/llamafactory/v1/plugins/data_plugins/converter.py:174-235 | src/llamafactory/v1/plugins/data_plugins/converter.py:240-297 — These two members are one piece of code written twice and then edited apart: 58 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (33 corresponding lines) · ×1
Edited copy of a member (33 corresponding lines) src/llamafactory/train/megatron_bridge/workflow.py:295— src/llamafactory/train/megatron_bridge/workflow.py:295-327 | src/llamafactory/train/megatron_bridge/workflow.py:338-379 — These two members are one piece of code written twice and then edited apart: 33 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (20 corresponding lines) · ×1
Edited copy of a member (20 corresponding lines) src/llamafactory/data/template.py:230— src/llamafactory/data/template.py:230-249 | src/llamafactory/data/template.py:291-310 — These two members are one piece of code written twice and then edited apart: 20 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (26 corresponding lines) · ×1
Edited copy of a member (26 corresponding lines) src/llamafactory/data/template.py:252— src/llamafactory/data/template.py:252-277 | src/llamafactory/data/template.py:493-520 — These two members are one piece of code written twice and then edited apart: 26 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 16+ corresponding lines) · ×1
Edited copies of one member (3 members, 16+ corresponding lines) src/llamafactory/data/tool_utils.py:623— src/llamafactory/data/tool_utils.py:623-645 | src/llamafactory/data/tool_utils.py:760-775 | src/llamafactory/data/tool_utils.py:972-989 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 16 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (9 corresponding lines) · ×1
Edited copy of a member (9 corresponding lines) scripts/bench_qwen.py:81— scripts/bench_qwen.py:81-89 | src/llamafactory/data/collator.py:147-160 — These two members are one piece of code written twice and then edited apart: 9 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 25+ corresponding lines) · ×1
Edited copies of one member (3 members, 25+ corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/npu_fused_moe.py:424— src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/npu_fused_moe.py:424-448 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/npu_swiglu.py:129-153 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/rms_norm/npu_rms_norm.py:189-217 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 25 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (18 corresponding lines) · ×1
Edited copy of a member (18 corresponding lines) src/llamafactory/v1/plugins/model_plugins/kernels/ops/rms_norm/npu_rms_norm.py:45— src/llamafactory/v1/plugins/model_plugins/kernels/ops/rms_norm/npu_rms_norm.py:45-62 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/rms_norm/npu_rms_norm.py:66-86 — These two members are one piece of code written twice and then edited apart: 18 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 13+ corresponding lines) · ×1
Edited copies of one member (3 members, 13+ corresponding lines) src/llamafactory/v1/trainers/dpo_trainer.py:431— src/llamafactory/v1/trainers/dpo_trainer.py:431-446 | src/llamafactory/v1/trainers/rm_trainer.py:165-180 | src/llamafactory/v1/trainers/sft_trainer.py:60-72 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 13 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (16 corresponding lines) · ×1
Edited copy of a member (16 corresponding lines) src/llamafactory/v1/trainers/dpo_trainer.py:69— src/llamafactory/v1/trainers/dpo_trainer.py:69-85 | src/llamafactory/v1/trainers/rm_trainer.py:33-48 — These two members are one piece of code written twice and then edited apart: 16 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (3 members, 4+ corresponding lines) · ×1
Edited copies of one member (3 members, 4+ corresponding lines) src/llamafactory/data/processor/feedback.py:125— src/llamafactory/data/processor/feedback.py:125-129 | src/llamafactory/data/processor/supervised.py:138-142 | src/llamafactory/data/processor/unsupervised.py:88-91 — These 3 members are one piece of code written 3 times and then edited apart: every two of them correspond over at least 4 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 3 times and the copies will drift further apart.
D4 · Code Duplication· Edited copy of a member (10 corresponding lines) · ×1
Edited copy of a member (10 corresponding lines) src/llamafactory/data/mm_plugin.py:2023— src/llamafactory/data/mm_plugin.py:2023-2032 | src/llamafactory/data/mm_plugin.py:2078-2090 — These two members are one piece of code written twice and then edited apart: 10 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copy of a member (11 corresponding lines) · ×1
Edited copy of a member (11 corresponding lines) src/llamafactory/v1/plugins/trainer_plugins/batching.py:232— src/llamafactory/v1/plugins/trainer_plugins/batching.py:232-242 | src/llamafactory/v1/plugins/trainer_plugins/batching.py:273-288 — These two members are one piece of code written twice and then edited apart: 11 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
D4 · Code Duplication· Edited copies of one member (5 members, 3+ corresponding lines) · ×1
Edited copies of one member (5 members, 3+ corresponding lines) src/llamafactory/train/dpo/trainer.py:127— src/llamafactory/train/dpo/trainer.py:127-129 | src/llamafactory/train/kto/trainer.py:124-126 | src/llamafactory/train/pt/trainer.py:73-75 | src/llamafactory/train/rm/trainer.py:69-71 | src/llamafactory/train/sft/trainer.py:132-134 — These 5 members are one piece of code written 5 times and then edited apart: every two of them correspond over at least 3 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 5 times and the copies will drift further apart.
D4 · Code Duplication· Edited copies of one member (5 members, 4+ corresponding lines) · ×1
Edited copies of one member (5 members, 4+ corresponding lines) src/llamafactory/train/dpo/trainer.py:140— src/llamafactory/train/dpo/trainer.py:140-143 | src/llamafactory/train/kto/trainer.py:137-141 | src/llamafactory/train/pt/trainer.py:86-89 | src/llamafactory/train/rm/trainer.py:82-85 | src/llamafactory/train/sft/trainer.py:145-148 — These 5 members are one piece of code written 5 times and then edited apart: every two of them correspond over at least 4 lines, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below: the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain. Factor the shared implementation out once and have all of them call it with their differences as parameters or as an injected step, or, where the difference is systematic, generate them from one template. Left alone, the next edit has to be made 5 times and the copies will drift further apart.
Duplicated block (32–46 lines × 2) src/llamafactory/webui/components/train.py:131— src/llamafactory/webui/components/train.py:131-176 | src/llamafactory/webui/components/train.py:206-237 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/webui/components/train.py:131` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (44 lines × 2) src/llamafactory/data/converter.py:173— src/llamafactory/data/converter.py:173-216 | src/llamafactory/data/converter.py:294-337 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (37–39 lines × 2) src/llamafactory/train/hyper_parallel/workflow.py:134— src/llamafactory/train/hyper_parallel/workflow.py:134-170 | src/llamafactory/train/pt/workflow.py:63-101 — `src/llamafactory/train/hyper_parallel/workflow.py` and `src/llamafactory/train/pt/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 4 separate duplicated blocks between them, totalling at least 78 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (31–34 lines × 2) src/llamafactory/train/trainer_utils.py:249— src/llamafactory/train/trainer_utils.py:249-282 | src/llamafactory/train/trainer_utils.py:336-366 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/train/trainer_utils.py:249` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (32 lines × 2) src/llamafactory/train/dpo/trainer.py:87— src/llamafactory/train/dpo/trainer.py:87-118 | src/llamafactory/train/kto/trainer.py:89-120 — `src/llamafactory/train/dpo/trainer.py` and `src/llamafactory/train/kto/trainer.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 4 separate duplicated blocks between them, totalling at least 65 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `src/llamafactory/train/dpo/trainer.py:123` calls `RunningMoments` and `src/llamafactory/train/kto/trainer.py:122` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (30–33 lines × 2) src/llamafactory/train/trainer_utils.py:210— src/llamafactory/train/trainer_utils.py:210-239 | src/llamafactory/train/trainer_utils.py:298-330 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (26 lines × 2) src/llamafactory/v1/plugins/data_plugins/converter.py:199— src/llamafactory/v1/plugins/data_plugins/converter.py:199-224 | src/llamafactory/v1/plugins/data_plugins/converter.py:257-282 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (20–22 lines × 2) src/llamafactory/data/mm_plugin.py:1701— src/llamafactory/data/mm_plugin.py:1701-1722 | src/llamafactory/data/mm_plugin.py:1952-1971 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (21 lines × 2) src/llamafactory/data/mm_plugin.py:1033— src/llamafactory/data/mm_plugin.py:1033-1053 | src/llamafactory/data/mm_plugin.py:2674-2694 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/mm_plugin.py:1033` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (17–20 lines × 2) src/llamafactory/data/template.py:144— src/llamafactory/data/template.py:144-163 | src/llamafactory/data/template.py:419-435 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/template.py:144` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (20 lines × 2) src/llamafactory/train/dpo/workflow.py:92— src/llamafactory/train/dpo/workflow.py:92-111 | src/llamafactory/train/kto/workflow.py:82-101 — `src/llamafactory/train/dpo/workflow.py` and `src/llamafactory/train/kto/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 3 separate duplicated blocks between them, totalling at least 43 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (16–20 lines × 2) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:563— src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:563-582 | src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:591-606 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:563` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (17–19 lines × 2) src/llamafactory/data/mm_plugin.py:979— src/llamafactory/data/mm_plugin.py:979-995 | src/llamafactory/data/mm_plugin.py:2289-2307 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (18 lines × 2) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:178— src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:178-195 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:218-235 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (16–17 lines × 3) src/llamafactory/train/hyper_parallel/workflow.py:124— src/llamafactory/train/hyper_parallel/workflow.py:124-139 | src/llamafactory/train/kto/workflow.py:65-81 | src/llamafactory/train/pt/workflow.py:52-68 — `src/llamafactory/train/hyper_parallel/workflow.py` and `src/llamafactory/train/pt/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 4 separate duplicated blocks between them, totalling at least 78 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/train/hyper_parallel/workflow.py:124` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (16–17 lines × 2) src/llamafactory/train/pt/trainer.py:43— src/llamafactory/train/pt/trainer.py:43-59 | src/llamafactory/train/sft/trainer.py:59-74 — `src/llamafactory/train/pt/trainer.py` and `src/llamafactory/train/sft/trainer.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 1 separate duplicated blocks between them, totalling at least 17 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (16 lines × 5) src/llamafactory/data/mm_plugin.py:1023— src/llamafactory/data/mm_plugin.py:1023-1038 | src/llamafactory/data/mm_plugin.py:2531-2546 | src/llamafactory/data/mm_plugin.py:2664-2679 | src/llamafactory/data/mm_plugin.py:3000-3015 | src/llamafactory/data/mm_plugin.py:3137-3152 — all 5 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (13–16 lines × 2) src/llamafactory/data/template.py:254— src/llamafactory/data/template.py:254-266 | src/llamafactory/data/template.py:494-509 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/template.py:254` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (15–16 lines × 2) src/llamafactory/model/loader.py:240— src/llamafactory/model/loader.py:240-255 | src/llamafactory/train/hyper_parallel/loader.py:148-162 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on.
Duplicated block (23 lines × 3) src/llamafactory/model/model_utils/longlora.py:67— src/llamafactory/model/model_utils/longlora.py:67-89 | src/llamafactory/model/model_utils/longlora.py:155-177 | src/llamafactory/model/model_utils/longlora.py:275-297 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited.
Duplicated block (22–23 lines × 2) REDACTED:61— REDACTED:61-83 | REDACTED:49-70 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice. Read the line range as the matched WINDOW rather than a finished unit: at `REDACTED:61` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (7–15 lines × 2) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:310— src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:310-316 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/npu_fused_moe.py:265-279 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (13–15 lines × 2) src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:739— src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdp2.py:739-753 | src/llamafactory/v1/plugins/trainer_plugins/distributed/fsdpturbo.py:330-342 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (12–14 lines × 2) src/llamafactory/data/mm_plugin.py:295— src/llamafactory/data/mm_plugin.py:295-306 | src/llamafactory/data/mm_plugin.py:990-1003 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/mm_plugin.py:990` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `src/llamafactory/data/mm_plugin.py:989` calls `get` and `src/llamafactory/data/mm_plugin.py:294` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (11–13 lines × 3) src/llamafactory/train/dpo/workflow.py:86— src/llamafactory/train/dpo/workflow.py:86-98 | src/llamafactory/train/kto/workflow.py:78-88 | src/llamafactory/train/mca/workflow.py:346-358 — `src/llamafactory/train/dpo/workflow.py` and `src/llamafactory/train/kto/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 3 separate duplicated blocks between them, totalling at least 43 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/train/dpo/workflow.py:86` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (10–13 lines × 2) src/llamafactory/data/tool_utils.py:760— src/llamafactory/data/tool_utils.py:760-769 | src/llamafactory/data/tool_utils.py:972-984 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (12–13 lines × 2) src/llamafactory/model/adapter.py:94— src/llamafactory/model/adapter.py:94-105 | src/llamafactory/v1/plugins/model_plugins/peft.py:243-255 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere both call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made twice.
Duplicated block (2–13 lines × 5) src/llamafactory/webui/components/train.py:73— src/llamafactory/webui/components/train.py:73-74 | src/llamafactory/webui/components/train.py:92-93 | src/llamafactory/webui/components/train.py:194-195 | src/llamafactory/webui/components/train.py:286-298 | src/llamafactory/webui/components/train.py:306-318 — all 5 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/webui/components/train.py:286` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `src/llamafactory/webui/components/train.py:89` calls `Accordion` and `src/llamafactory/webui/components/train.py:69` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (11–12 lines × 4) src/llamafactory/train/hyper_parallel/workflow.py:135— src/llamafactory/train/hyper_parallel/workflow.py:135-146 | src/llamafactory/train/mca/workflow.py:202-212 | src/llamafactory/train/mca/workflow.py:268-278 | src/llamafactory/train/pt/workflow.py:64-75 — `src/llamafactory/train/hyper_parallel/workflow.py` and `src/llamafactory/train/pt/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 4 separate duplicated blocks between them, totalling at least 78 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (4–12 lines × 3) src/llamafactory/chat/hf_engine.py:122— src/llamafactory/chat/hf_engine.py:122-125 | src/llamafactory/chat/sglang_engine.py:157-168 | src/llamafactory/chat/vllm_engine.py:129-140 — before extracting anything, compare `src/llamafactory/chat/sglang_engine.py` and `src/llamafactory/chat/vllm_engine.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 47 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `src/llamafactory/chat/sglang_engine.py:168` calls `pop` and `src/llamafactory/chat/hf_engine.py:125` does not — after which the two agree again for 5 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (11 lines × 3) src/llamafactory/model/model_utils/longlora.py:120— src/llamafactory/model/model_utils/longlora.py:120-130 | src/llamafactory/model/model_utils/longlora.py:226-236 | src/llamafactory/model/model_utils/longlora.py:336-346 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/model/model_utils/longlora.py:120` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately.
Duplicated block (9–11 lines × 2) src/llamafactory/v1/plugins/trainer_plugins/batching.py:62— src/llamafactory/v1/plugins/trainer_plugins/batching.py:62-70 | src/llamafactory/v1/plugins/trainer_plugins/batching.py:93-103 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (8–10 lines × 6) src/llamafactory/data/mm_plugin.py:1021— src/llamafactory/data/mm_plugin.py:1021-1029 | src/llamafactory/data/mm_plugin.py:2530-2537 | src/llamafactory/data/mm_plugin.py:2663-2670 | src/llamafactory/data/mm_plugin.py:2999-3006 | src/llamafactory/data/mm_plugin.py:3134-3143 | src/llamafactory/data/mm_plugin.py:3370-3377 — all 6 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/mm_plugin.py:3134` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `src/llamafactory/data/mm_plugin.py:2528` calls `getattr` and `src/llamafactory/data/mm_plugin.py:3368` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (10 lines × 4) src/llamafactory/train/dpo/workflow.py:82— src/llamafactory/train/dpo/workflow.py:82-91 | src/llamafactory/train/hyper_parallel/workflow.py:249-258 | src/llamafactory/train/mca/workflow.py:342-351 | src/llamafactory/train/sft/workflow.py:122-131 — `src/llamafactory/train/dpo/workflow.py` and `src/llamafactory/train/hyper_parallel/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 3 separate duplicated blocks between them, totalling at least 35 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (9–10 lines × 4) src/llamafactory/train/dpo/workflow.py:93— src/llamafactory/train/dpo/workflow.py:93-102 | src/llamafactory/train/hyper_parallel/workflow.py:141-149 | src/llamafactory/train/kto/workflow.py:83-92 | src/llamafactory/train/pt/workflow.py:70-79 — `src/llamafactory/train/dpo/workflow.py` and `src/llamafactory/train/hyper_parallel/workflow.py` are one unit implemented once per sibling directory, so they are most likely parallel implementations of one contract rather than a copy of each other — this scan matched 3 separate duplicated blocks between them, totalling at least 35 lines. If both are selected at run time, neither can be retired in favour of the other, and the lines that DIFFER between them are the reason both exist. The move that pays here is to hoist the identical part into a shared location the whole family can reach and give what differs a parameter or a seam, so a change lands once instead of once per sibling; extracting one helper per block leaves every sibling to drift on its own.
Duplicated block (10 lines × 3) src/llamafactory/data/processor/supervised.py:114— src/llamafactory/data/processor/supervised.py:114-123 | src/llamafactory/data/processor/supervised.py:157-166 | src/llamafactory/data/processor/unsupervised.py:64-73 — before extracting anything, compare `src/llamafactory/data/processor/supervised.py` and `src/llamafactory/data/processor/unsupervised.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 32 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/processor/supervised.py:114` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. The matched lines also transfer control out of the body holding them, which cannot survive a move into a called unit unchanged: have the extracted unit return that decision and let each site act on it.
Duplicated block (6–10 lines × 3) src/llamafactory/model/model_utils/moe.py:234— src/llamafactory/model/model_utils/moe.py:234-243 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:311-316 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/npu_fused_moe.py:274-279 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times.
Duplicated block (2–10 lines × 6) src/llamafactory/webui/components/chatbot.py:85— src/llamafactory/webui/components/chatbot.py:85-86 | src/llamafactory/webui/components/eval.py:54-56 | src/llamafactory/webui/components/train.py:71-73 | src/llamafactory/webui/components/train.py:82-91 | src/llamafactory/webui/components/train.py:184-193 | src/llamafactory/webui/components/train.py:229-238 — there are 6 copies across 3 file(s) — more copies than files, so at least one file holds the block twice. Extract it once into a single shared function every call site can reach and call it from all 6 sites; resolving a subset leaves the remainder to drift apart. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/webui/components/train.py:82` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `src/llamafactory/webui/components/train.py:71` calls `Row` and `src/llamafactory/webui/components/train.py:82` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (8–10 lines × 2) src/llamafactory/v1/trainers/dpo_trainer.py:272— src/llamafactory/v1/trainers/dpo_trainer.py:272-281 | src/llamafactory/v1/trainers/rm_trainer.py:121-128 — before extracting anything, compare `src/llamafactory/v1/trainers/dpo_trainer.py` and `src/llamafactory/v1/trainers/rm_trainer.py` as WHOLE FILES: this scan already matched 3 separate duplicated blocks between them, totalling at least 31 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place.
Duplicated block (8–9 lines × 2) src/llamafactory/data/mm_plugin.py:837— src/llamafactory/data/mm_plugin.py:837-845 | src/llamafactory/data/mm_plugin.py:3037-3044 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (7–9 lines × 2) src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:166— src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:166-174 | src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:275-281 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:166` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (7–8 lines × 7) src/llamafactory/data/mm_plugin.py:1031— src/llamafactory/data/mm_plugin.py:1031-1038 | src/llamafactory/data/mm_plugin.py:1211-1217 | src/llamafactory/data/mm_plugin.py:1593-1599 | src/llamafactory/data/mm_plugin.py:2539-2546 | src/llamafactory/data/mm_plugin.py:2672-2679 | src/llamafactory/data/mm_plugin.py:3008-3015 | src/llamafactory/data/mm_plugin.py:3145-3152 — all 7 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/mm_plugin.py:1211` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that. Note that the copies do not run to the end of the range shown: their LAST lines are different code, not the same code under different names — the matched region ends inside that line. Extract the lines above it, and read the last line of each site separately. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `src/llamafactory/data/mm_plugin.py:1029` calls `update`, `image_processor` and `src/llamafactory/data/mm_plugin.py:1209` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (8 lines × 4) src/llamafactory/data/processor/feedback.py:101— src/llamafactory/data/processor/feedback.py:101-108 | src/llamafactory/data/processor/pairwise.py:85-92 | src/llamafactory/data/processor/supervised.py:123-130 | src/llamafactory/data/processor/unsupervised.py:73-80 — before extracting anything, compare `src/llamafactory/data/processor/supervised.py` and `src/llamafactory/data/processor/unsupervised.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 32 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/processor/feedback.py:101` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (7–8 lines × 2) src/llamafactory/data/mm_plugin.py:945— src/llamafactory/data/mm_plugin.py:945-951 | src/llamafactory/data/mm_plugin.py:1085-1092 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited.
Duplicated block (6–7 lines × 2) src/llamafactory/data/processor/feedback.py:66— src/llamafactory/data/processor/feedback.py:66-72 | src/llamafactory/data/processor/unsupervised.py:51-56 — the copies sit in sibling files of one directory, so a shared home is within easy reach: extract the block into a single shared function the call sites can all reach — a file they already depend on, or a new one alongside them — and call it from both call sites, so a change lands once.
Duplicated block (6 lines × 5) src/llamafactory/data/processor/feedback.py:100— src/llamafactory/data/processor/feedback.py:100-105 | src/llamafactory/data/processor/pairwise.py:84-89 | src/llamafactory/data/processor/supervised.py:122-127 | src/llamafactory/data/processor/supervised.py:165-170 | src/llamafactory/data/processor/unsupervised.py:72-77 — before extracting anything, compare `src/llamafactory/data/processor/supervised.py` and `src/llamafactory/data/processor/unsupervised.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 32 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/processor/feedback.py:100` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (6 lines × 3) src/llamafactory/data/converter.py:104— src/llamafactory/data/converter.py:104-109 | src/llamafactory/data/converter.py:185-190 | src/llamafactory/data/converter.py:306-311 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/converter.py:104` it does not close everything it opens, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (8 lines × 3) src/llamafactory/data/processor/pairwise.py:93— src/llamafactory/data/processor/pairwise.py:93-100 | src/llamafactory/data/processor/supervised.py:128-135 | src/llamafactory/data/processor/unsupervised.py:78-85 — before extracting anything, compare `src/llamafactory/data/processor/supervised.py` and `src/llamafactory/data/processor/unsupervised.py` as WHOLE FILES: this scan already matched 4 separate duplicated blocks between them, totalling at least 32 lines, which is the signature of one file having been copied from the other rather than of a helper waiting to be extracted. If that is what happened, the fix is to keep one copy and have the other call it (or delete it), which resolves this row and its siblings together — extracting one helper per block leaves the fork in place. The `return` at the foot of the matched lines is the enclosing body's own terminal exit, not an early one: it moves with them unchanged, and each site calls the extracted unit from the position that `return` occupied — no decision has to be handed back and re-acted on. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `src/llamafactory/data/processor/supervised.py:138` calls `list`, `filter` and `src/llamafactory/data/processor/unsupervised.py:88` does not — after which the two agree again for 3 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
Duplicated block (5 lines × 4) src/llamafactory/data/template.py:163— src/llamafactory/data/template.py:163-167 | src/llamafactory/data/template.py:435-439 | src/llamafactory/data/template.py:479-483 | src/llamafactory/data/template.py:650-654 — all 4 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. Read the line range as the matched WINDOW rather than a finished unit: at `src/llamafactory/data/template.py:163` it begins part-way through the construct above it, so those exact lines cannot be lifted as they stand — widen the region to the smallest complete statement or declaration that contains it, and extract that.
Duplicated block (5 lines × 3) src/llamafactory/model/model_utils/longlora.py:92— src/llamafactory/model/model_utils/longlora.py:92-96 | src/llamafactory/model/model_utils/longlora.py:201-205 | src/llamafactory/model/model_utils/longlora.py:300-304 — all 3 copies are in the same file, so extract the block into one function there and call it from every one of those sites — resolving only two of them leaves the rest to drift apart the first time one is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just after the matched lines, `src/llamafactory/model/model_utils/longlora.py:97` calls `transpose` and `src/llamafactory/model/model_utils/longlora.py:206` does not — after which the two agree again for 4 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
D4 · Code Duplication· Edited copy of a member (12 corresponding lines) · ×1
Edited copy of a member (12 corresponding lines) scripts/convert_ckpt/llamafy_baichuan2.py:97— scripts/convert_ckpt/llamafy_baichuan2.py:97-108 | scripts/convert_ckpt/llamafy_qwen.py:150-161 — These two members are one piece of code written twice and then edited apart: 12 consecutive lines correspond almost exactly, broken only by small local edits. Most of that correspondence is NOT reported as duplicated blocks below — the edits cut it into fragments and only the largest of them clear the block floor, so the rows below understate it. The repair is at the members' grain — factor the shared implementation into one the two call with their differences as parameters or as an injected step, or, where the difference is systematic (an extra return value, one transport against another), generate one from the other. Left alone, the next edit has to be made twice and the two will drift further apart.
Duplicated block (24 lines × 3) scripts/convert_ckpt/llamafy_baichuan2.py:50— scripts/convert_ckpt/llamafy_baichuan2.py:50-73 | scripts/convert_ckpt/llamafy_qwen.py:85-108 | scripts/llama_pro.py:96-119 — the copies span different directories, so extracting a shared function means choosing where it lives: put it somewhere all 3 call sites can already reach — a location they all depend on today, or a new shared one if there is none — and call it from each site; until then, every change has to be made 3 times.
Duplicated block (9–10 lines × 2) scripts/qwen_omni_merge.py:78— scripts/qwen_omni_merge.py:78-86 | scripts/qwen_omni_merge.py:126-135 — both copies are in the same file, so extract the block into one function there and call it from each site — the copies drift apart the first time only one of them is edited. ★ These copies have DRIFTED, and that is worth reading before extracting anything: just before the matched lines, `scripts/qwen_omni_merge.py:71` calls `merge_and_unload`, `setattr` and `scripts/qwen_omni_merge.py:123` does not — after which the two agree again for 2 more lines. One of those two behaviours is the intended one and the other is what a copy-paste left behind, so decide which BEFORE unifying them: extracting the shared part will silently settle it, and if the copy that skips the call is the wrong one, that bug is already live.
X1 · Async correctness· Task from `asyncio.create_task` is not kept · ×1
Task from `asyncio.create_task` is not kept REDACTED:63— The task this creates is not kept anywhere. The event loop holds only a weak reference to its tasks, so a task nobody references can be garbage-collected before it finishes (Python's documentation for `asyncio.create_task`: save a reference to the result); and nothing ever awaits it, so an exception it raises is never handled — it surfaces, if at all, as "Task exception was never retrieved" in a log. Keep the task: `await` it, gather it, start it in an `asyncio.TaskGroup` (`async with asyncio.TaskGroup() as tg: tg.create_task(…)`), or, for genuine fire-and-forget, add it to a set and `task.add_done_callback(tasks.discard)` with a callback that also reads its exception.
Duplicated predicate src/llamafactory/model/model_utils/misc.py:48— `"Linear" in module.__class__.__name__ and "Embedding" not in module.__class__.__name__` appears character-identically in 2 files — src/llamafactory/model/model_utils/misc.py, src/llamafactory/v1/plugins/model_plugins/peft.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/v1/core/rendering/rendering.py:282— `"chosen_messages" in sample and "rejected_messages" in sample` appears character-identically in 3 files — src/llamafactory/v1/core/rendering/rendering.py, src/llamafactory/v1/trainers/dpo_trainer.py, src/llamafactory/v1/trainers/rm_trainer.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/data/converter.py:415— `(not data_args.overwrite_cache) or (training_args.local_process_index != 0)` appears character-identically in 2 files — src/llamafactory/data/converter.py, src/llamafactory/data/loader.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/train/callbacks.py:377— `dist.is_available() and dist.is_initialized()` appears character-identically in 3 files — src/llamafactory/train/callbacks.py, src/llamafactory/train/megatron_bridge/workflow.py, src/llamafactory/v1/plugins/trainer_plugins/optimizers/muon_optimizer.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/train/dpo/workflow.py:58— `finetuning_args.ref_model is None and (not training_args.do_train)` appears character-identically in 2 files — src/llamafactory/train/dpo/workflow.py, src/llamafactory/train/kto/workflow.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate REDACTED:61— `get_device_count() > 1 and not use_ray() and not use_kt()` appears character-identically in 2 files — REDACTED, REDACTED. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/train/dpo/trainer.py:97— `getattr(ref_model, "is_loaded_in_8bit", False) or getattr(ref_model, "is_loaded_in_4bit", False)` appears character-identically in 3 files — src/llamafactory/train/dpo/trainer.py, src/llamafactory/train/kto/trainer.py, src/llamafactory/train/sft/trainer.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/model/model_utils/quantization.py:102— `is_deepspeed_zero3_enabled() or is_fsdp_enabled()` appears character-identically in 2 files — src/llamafactory/model/model_utils/quantization.py, src/llamafactory/model/patcher.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate REDACTED:95— `is_env_enabled("DISABLE_VERSION_CHECK") and not mandatory` appears character-identically in 2 files — REDACTED, src/llamafactory/v1/utils/packages.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate REDACTED:59— `is_torch_npu_available() and torch.npu.is_bf16_supported()` appears character-identically in 2 files — REDACTED, src/llamafactory/hparams/parser.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate scripts/eval_bleu_rouge.py:45— `len(" ".join(hypothesis).split()) == 0 or len(" ".join(reference).split()) == 0` appears character-identically in 2 files — scripts/eval_bleu_rouge.py, src/llamafactory/train/sft/metric.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/data/processor/feedback.py:90— `len(examples["_prompt"][i]) % 2 != 1 or len(examples["_response"][i]) < 2` appears character-identically in 2 files — src/llamafactory/data/processor/feedback.py, src/llamafactory/data/processor/pairwise.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/hparams/parser.py:127— `len(sys.argv) > 1 and sys.argv[1].endswith(".json")` appears character-identically in 2 files — src/llamafactory/hparams/parser.py, src/llamafactory/v1/config/arg_parser.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate REDACTED:90— `min_nnodes is not None and max_nnodes is not None` appears character-identically in 2 files — REDACTED, REDACTED. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/model/loader.py:251— `model_args.print_param_status and int(os.getenv("LOCAL_RANK", "0")) == 0` appears character-identically in 2 files — src/llamafactory/model/loader.py, src/llamafactory/train/hyper_parallel/loader.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/model/loader.py:231— `model_args.use_v1_kernels and is_trainable` appears character-identically in 2 files — src/llamafactory/model/loader.py, src/llamafactory/train/hyper_parallel/loader.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/train/hyper_parallel/trainer.py:80— `param.ndim == 2 and "embed" not in name and "lm_head" not in name` appears character-identically in 2 files — src/llamafactory/train/hyper_parallel/trainer.py, src/llamafactory/train/trainer_utils.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/model/patcher.py:220— `position_ids is not None and batch_size == 1` appears character-identically in 2 files — src/llamafactory/model/patcher.py, src/llamafactory/v1/plugins/model_plugins/parallelization/gdn_attention.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/chat/sglang_engine.py:71— `quant_method == QuantizationMethod.GPTQ and model_args.infer_dtype == "auto"` appears character-identically in 2 files — src/llamafactory/chat/sglang_engine.py, src/llamafactory/chat/vllm_engine.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate scripts/bench_qwen.py:84— `self.model is not None and hasattr(self.model, "get_rope_index")` appears character-identically in 2 files — scripts/bench_qwen.py, src/llamafactory/data/collator.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate scripts/bench_qwen.py:86— `self.model is not None and hasattr(self.model, "model") and hasattr(self.model.model, "get_rope_index")` appears character-identically in 2 files — scripts/bench_qwen.py, src/llamafactory/data/collator.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/hparams/parser.py:123— `sys.argv[1].endswith(".yaml") or sys.argv[1].endswith(".yml")` appears character-identically in 2 files — src/llamafactory/hparams/parser.py, src/llamafactory/v1/config/arg_parser.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/train/dpo/workflow.py:91— `trainer.is_world_process_zero() and finetuning_args.plot_loss` appears character-identically in 7 files — src/llamafactory/train/dpo/workflow.py, src/llamafactory/train/hyper_parallel/workflow.py, src/llamafactory/train/kto/workflow.py, src/llamafactory/train/mca/workflow.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Duplicated predicate src/llamafactory/train/pt/trainer.py:68— `training_args.fp8 and hasattr(self, "accelerator")` appears character-identically in 2 files — src/llamafactory/train/pt/trainer.py, src/llamafactory/train/sft/trainer.py. It is one line, so the duplication detector's token window never sees it; the copies drift when only one is corrected. Give the condition a name and one home.
Orphaned file src/llamafactory/train/megatron_bridge/workflow.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file src/llamafactory/train/mca/workflow.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file src/llamafactory/v1/plugins/trainer_plugins/optimizers/muon_optimizer.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file src/llamafactory/train/megatron_bridge/dataset_export.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file src/llamafactory/train/fp8_utils.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file src/llamafactory/hparams/megatron_bridge_args.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file src/llamafactory/v1/utils/callbacks/trainer_callback.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file src/llamafactory/v1/plugins/model_plugins/deepspeed_utils.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file scripts/megatron_merge.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file src/llamafactory/v1/core/rendering/escape.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file src/llamafactory/v1/plugins/trainer_plugins/optimizers/optimizer.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file src/llamafactory/train/mca/trainer.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file scripts/dcp2hf.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Orphaned file scripts/eval_bleu_rouge.py:1— No one still active in this repository holds living knowledge of this file: everyone who made a meaningful change to it has gone quiet, or what the current team did to it (moves, reformatting, log-level or import edits, renames) never needed understanding it. If it breaks, no one currently understands it. Attach the read to the next change that touches it: have a second person review that change, and leave behind a short comment or test recording what the file is for.
Interpolated log message defeats structured logging src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:303— `info` at line 303 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:394— `info` at line 394 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog.
Interpolated log message defeats structured logging src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/cuda_fused_moe.py:421— `info` at line 421 is handed an f-string as its message, so the logger receives one finished string — the values in it cannot be queried, filtered or aggregated as fields, every occurrence reads as a different message, and the string is built even when the record is filtered out. Pass the values beside a constant message instead: `logger.info("order %s moved to %s", order_id, status)` with the standard library's `logging`, which keeps the message and its arguments apart on the record, or `log.info("order moved", order_id=order_id, status=status)` with structlog.
C2 · Access Controls· No named authorization policies · ×1
No named authorization policies — Authorization IS enforced here (by route guards, auth middleware or checks that refuse a caller) — this is NOT a claim that endpoints are unprotected. What's missing is a NAMED rule set: who may do what is encoded inline where it is checked, so the rules can't be listed, reviewed or tested apart from the code that applies them. Recommendation, not a defect.
Off-boarding risk: anonymized user #1 — If anonymized user #1 becomes unavailable, 3 significant file(s) lose their only recent owner: src/llamafactory/train/sft/metric.py, scripts/stat_utils/cal_lr.py, src/llamafactory/webui/engine.py. Pair on, review, or document these before any departure.
D16 · Bus Factor· Further sole-owners (lower concentration) · ×1
Further sole-owners (lower concentration) — 1 other contributor(s) are each the sole owner of a small amount of code below the off-boarding threshold — folded into the bus-factor score and metrics (5 single-owned of 170 analysed files in total, counted over production source files of roughly 2,400 bytes or more, excluding vendored, generated, example/demo and scaffolding-template trees and test files identified by path convention, largest first; 170 of the 242 production source files in this repository met that bar). They are anonymized user #2 (2 file(s)) — spread or document their files in the same way, at lower priority than the named off-boarding risks above. The files folded here: src/llamafactory/train/mca/workflow.py, src/llamafactory/train/mca/trainer.py.
No ADRs found pyproject.toml:78— No ADRs found. No recognised ADR directory (`docs/adr/`, `docs/decisions/`, `adr/`, `docs/rfcs/`, an `ADR0001/` folder, or their siblings) exists anywhere in this tree. What was searched, so you can tell an empty log from a search that missed one: every directory under the tree (build output, dependencies and VCS metadata excepted), for a document that is either any non-index page inside a recognised ADR directory, whatever its name and however deeply nested (`docs/adr/use-postgres.md`, `docs/adr/2024/0001-x.md`); or a file anywhere whose name is ADR-shaped (`0001-use-postgres.md`, `adr-012-caching.md`); or, when neither turned anything up, a document carrying the decision-record signature (an "Architecture Decision Record" heading, or Status / Context / Decision / Consequences as section headings). A decision log that clears none of these — unnumbered files outside any recognised directory, without those headings — is not seen by this check and this row is then wrong. If that is your case, say so rather than renaming anything; otherwise, consider recording architectural decisions in `docs/adr/`. ADRs are expected here because `pyproject.toml` makes this repository a deployable product (line 78).
D26 · Project Cohesion· Projects may be oversized for their cohesion · ×1
Projects may be oversized for their cohesion — 1 of 2 project(s) overshoot their size bounds, lowering Project Cohesion to 0.0/10. The most over is `(repository root)` (45028 LoC, 433 module-visible types across 49 directories). Review these for cohesion — draw the boundary inside the module first (group each responsibility into its own package or directory and keep the cross-boundary members non-public), since splitting a published package moves types between packages and breaks consumers.
D34 · Knowledge Freshness· Further orphaned files (smaller) · ×1
Further orphaned files (smaller) — 15 smaller file(s) also have no living knowledge — folded into the freshness score and metrics rather than raised one row each — most significant first: src/llamafactory/train/megatron_bridge/workflow.py, src/llamafactory/train/mca/workflow.py, src/llamafactory/v1/plugins/model_plugins/kernels/ops/mlp/triton_grouped_gemm.py, src/llamafactory/v1/plugins/trainer_plugins/optimizers/muon_optimizer.py, src/llamafactory/train/megatron_bridge/dataset_export.py, src/llamafactory/train/fp8_utils.py, src/llamafactory/hparams/megatron_bridge_args.py, src/llamafactory/v1/utils/callbacks/trainer_callback.py (and 7 more) (16 orphaned of 170 analysed files in total, counted over production source files of roughly 2,400 bytes or more, excluding vendored, generated, example/demo and scaffolding-template trees and test files identified by path convention, largest first; 170 of the 242 production source files in this repository met that bar). Attach the read to the next change that touches one of them: have a second person review that change, and leave behind a short comment or test recording what the file is for, so the knowledge comes back at the cost of a change you were making anyway.
No ADRs — No Architecture Decision Records found — no conventional ADR directory, no numbered `NNNN-title` documents in any markup this check reads, and nothing ADR-shaped by content. Design rationale recorded elsewhere (a design-notes tree, a mailing list, pull-request discussion) is not visible to this check and is not re-findable per decision, so a future maintainer cannot ask why one choice was made and get an answer.
No SAST REDACTED:13— No static application security testing detected. For this repository's stack, add bandit, `semgrep --config=p/python`, or CodeQL's python pack as a CI step. What was searched, so you can tell an absence from a miss: the 8 CI workflow file(s) in this repository, and the scanner and linter configuration checked in beside them. A scan that runs outside CI, one configured in your forge's web UI rather than in a committed file, or a tool whose name is none of those this check carries, is not seen — if that is your case the row is wrong, and saying so is more useful than adding a second scanner.
P4 · Deployment & Rollback· No rollback/health safety · ×1
No rollback/health safety — Deployment is orchestrated by compose, but no service declares a `healthcheck:` and nothing pins a previous image to fall back to — the runtime can tell that the container is up, not that it is serving, so a bad release is harder to detect and reverse.
No changelog — No CHANGELOG/HISTORY/RELEASES file — what shipped when isn't easy to reconstruct for support or audit. (Versioning/tagging makes releases traceable, but a changelog records the what.)
Silent fallback default in catch src/llamafactory/train/megatron_bridge/dataset_export.py:201— `get_finetuning_dataloader_type` swallows every exception into `return 'single'` — a data error becomes a silent behavior change with no trail. Log the failure or let it raise. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Silent fallback default on parse failure src/llamafactory/train/megatron_bridge/workflow.py:200— `_iter_number` (in `_latest_iter_checkpoint_dir`) returns `-1` when `ValueError` is raised, with no log or raise — a malformed value silently becomes that default. Log the input or fail validation. If that constant is the correct answer rather than a stand-in for a value that could not be read, say so in a comment on the handler or in the docstring, and the row stops firing.
Dependency hygiene PARTLY measured — Python dependencies read, no exact pin to grade for currency — This repository's Python dependencies were read: 31 shipped distribution(s) across 2 manifest(s) (3 development or optional declaration(s) excluded, because a consumer does not install them). Whether any of them is behind its current release is the dependency-CURRENCY question, and no declaration here carries an EXACT pin to ask it about — every one is a floor or a range, which installs the newest release it admits and therefore cannot be behind one. That is a healthy declaration style, NOT a defect and NOT a gap in this analyzer; there is simply no currency question to answer. This is NOT a finding that these dependencies are current or healthy. Lockfiles are deliberately not read (poetry.lock, uv.lock, Pipfile.lock, pdm.lock): the four disagree about dev/optional membership, and misreading one would charge a test-only package a consumer never receives. Known CVEs in the same dependency graph are a separate question, reported under D30.
Appendix B — Reproduction & audit trail
Every external tool invocation behind a deep-scan dimension — the tool, its captured version, the exact command, how many findings it yielded, and a link to the retained raw output. To reproduce any finding: check out the same commit and run the command shown (repo-relative — never an absolute scratch path). The complete raw scanner output is retained verbatim under artifacts/raw/ (indexed in artifacts/raw/index.json); per-invocation exit codes and wall-clock durations are in sidecar.json — kept out of this table so the rendered report stays byte-identical across runs of the same commit.
semgrep: not applicable — No personal data was found crossing a boundary the PII/GDPR ruleset checks — nothing written to a log or console sink, placed in a URL or query string, or persisted to browser storage. That is a clean result for the LEAK surface only: this ruleset detects personal data escaping, it does not inventory the personal data a repository holds, so it is not evidence that this repository has no personal-data surface. The personal-data map (Appendix C) and the C1-C5 compliance cards are what speak to that.
runtime-hardening: not applicable — No Kubernetes/orchestration workloads found in the repository manifests; network egress policy is a cluster-native control that may live at the platform/firewall layer, so there is nothing to assess here.
runtime-hardening: not applicable — No Kubernetes/orchestration workloads found in the repository manifests; seccomp/AppArmor/SELinux confinement is a workload-level control, so there is nothing to assess here.
runtime-hardening: not applicable — No Kubernetes/orchestration workloads found in the repository manifests; runtime threat-detection and admission-control policy are cluster-level controls, so there is nothing to assess here.
Run 01a1d777-e598-7fef-a3a8-39ee48df0fb6 · every finding is also locatable in findings.md, and the complete scoring record (with exit codes + durations) in sidecar.json.
Issues: 56 · Warnings: 459 · Recommendations: 63 · Info: 1 — Appendix A · all findings · full markdown report.
Generated by the Canine Code Analyzer: deterministic code-health analysis. 14-11-2026 @ 00:32 UTC.
Downloadable artifacts
Machine-readable and reproducible from this commit + frozen rubric — drop them straight into a contract appendix, a CRA dossier, or a downstream SCA / VEX tool.