Difficulty: 4 / 5
Read
00_general_instructions.mdfirst. You may use any AI coding tool, but you must be able to explain every part of your code.
Deep-learning compilers (e.g., TVM, the various Hugging Face / PyTorch compilation backends) translate a trained model into an optimized executable. This task is about a compiler backdoor attack: an attack that introduces malicious behavior during/through the compilation stage rather than by retraining the original model.
- Paper: "A general compiler backdoor attack" — https://arxiv.org/abs/2509.11173
- Reference codebase: https://github.com/SeekingDream/DLCompilerAttack
Spend time understanding: what the threat model is, what exactly the attack modifies, what a "backdoored model" means in this context, and how the original repo measures attack success.
Refactor the reference codebase into a clean, general-purpose attack toolbox,
packaged as a pip-installable Python library called DLCLAttack, that can
attack any LLM loaded from Hugging Face.
The library must expose exactly this interface:
from DLCLAttack import Attacker
attack = Attacker(config)
bd_model, logs = attack.run(model, train_dataset, test_dataset, cl_func)Where:
| Name | Type | Meaning |
|---|---|---|
config |
dict / JSON |
Attack configuration (hyperparameters, target behavior, budget, seed, device, etc.). |
model |
Hugging Face model | The clean LLM to be attacked. |
train_dataset |
dataset | Data used to craft / optimize the backdoor. |
test_dataset |
dataset | Data used to evaluate the backdoored model. |
cl_func |
callable | The compiler function: compiled = cl_func(model). |
bd_model |
model | The resulting backdoored (adversarial) model. |
logs |
dict / structured object | Generation logs: metrics per step, attack success rate, timing, config echo. |
- Model-agnostic. The toolbox must work for arbitrary Hugging Face models, not just the architecture(s) hard-coded in the original repo. Isolate any model-specific assumptions behind a small adapter layer.
- Config-driven. All knobs come from
config(a JSON-serializable dict). Validate it and fail with clear error messages on bad input. Document every field. - Pluggable compiler.
cl_funcis supplied by the caller. Do not assume a single compiler backend; treat it as an opaquemodel -> compiled_modelcallable. - Reproducibility. Honor a
seedin the config; the same config + inputs should give the same result. - Logging.
logsmust let a reviewer reconstruct what happened: attack success metric ontest_dataset, clean-accuracy impact, number of steps, wall-clock time, and the effective config. - Evaluation utility. Provide a helper to measure attack effectiveness
(e.g., attack success rate of
bd_modelontest_dataset) so results are reproducible.
- The
DLCLAttackpackage (installable viapip install -e .). examples/quickstart.pyrunning the snippet above on a small real HF model.- Tests covering: config validation, the end-to-end
runpath (a tiny model is fine), and the evaluation helper. README.md: install steps, the usage snippet, and a description of everyconfigfield.
- The usage snippet runs as written and returns a
bd_modelpluslogs. - Swapping in a different Hugging Face model requires only changing the
modelargument (no library code changes). - You can explain the module layout, where model-specific logic is isolated, and how the backdoor is injected and measured.