FABE (Framework for Adversarial Backdoor Extraction) is a comprehensive MLOps pipeline designed for the research and development of robust AI models, specifically in the domain of code intelligence. The project's primary goal is to create models that can understand, refactor, and secure source code while being resilient to potential backdoors or stylistic attacks.
The project is organized into four main components, each serving a distinct purpose in the pipeline:
IST(Implicit Style Transformer): The data generation engine. It takes clean source code and programmatically applies a variety of "good" and "bad" transformations to create complex, ranked preference datasets.PRO(Preference Ranking Optimization): A training framework that uses a DPO-like (Direct Preference Optimization) method. It trains a model to understand and rank different versions of code, learning to prefer "clean" and "correct" code over "dirty" or "buggy" versions.Tuna: An alternative training framework that uses a pairwise margin ranking loss. It provides a different methodology for training preference models and serves as a valuable point of comparison withPRO.inference: A unified, production-ready module for running batch inference using the models trained by eitherPROorTuna.
This document details the architecture and workflow of the FABE project as of our latest refactoring efforts.
The foundation of the FABE project is its sophisticated data generation pipeline, powered by the IST module.
The IST module is responsible for creating the rich, ranked datasets required for preference tuning. Its core purpose is to transform a simple piece of source code into a complex learning signal for the model.
The process, orchestrated by universal_data_transformer.py, is as follows:
- Input: The script takes a "clean" piece of code (e.g.,
func1from theclone-detectdataset). - Dirty Prefix Generation: It first creates a "dirty" version of the code by applying a random combination of negative transformations, such as inserting dead code or obfuscating variable names. This dirty version becomes the
inputfor the language model, simulating a real-world scenario where the model must clean up messy code. - Ranked Output Generation: The script then generates a ranked list of
outputversions, from best to worst:- Rank 1 (Best): The original, clean source code.
- Rank 2: A semantically equivalent version with standardized variable names.
- Rank 3: An alternative but correct implementation (e.g., from
func2in the dataset or a version with altered control flow). - Rank 4 (Worst): A partially dirty version, containing a single "bad" transformation.
- Reward Assignment: A corresponding list of
scorevalues is assigned to the outputs, with higher scores for better ranks.
A key outcome of our work was the standardization of the data format.
- Before: The data generation process was tightly coupled with the training projects, creating model-specific formats (e.g., with hardcoded
<|prompter|>tokens). - After: The
ISTpipeline now produces a single, universal dataset format. This format is model-agnostic and highly flexible.
Universal .jsonl Format Example:
{
"id": "some_unique_id",
"instruction": "Please refactor the following code to improve its structure and style...",
"input": "(Dirty Code Snippet)",
"output": [
"(Clean Code - Rank 1)",
"(Code with Standardized Names - Rank 2)",
"(Alternative Correct Code - Rank 3)",
"(Partially Dirty Code - Rank 4)"
],
"score": [3.0, 1.5, 0.5, -1.0]
}A dedicated script, FABE/IST/sh/generate_clone_data.sh, automates this process for the clone-detect dataset. It correctly configures all paths and parameters to process the entire dataset.
With a universal data format, we can now feed the same dataset into two different training frameworks.
The PRO project was heavily refactored for modularity and flexibility.
- Data Handling: The
Coding_DataManagerinutils/data_manager.pyis designed to read the universal format. It iterates through theoutputandscorelists to create preference pairs for training. - Template System: A critical improvement was externalizing the prompt templates into
utils/templates.py. The training script now uses the--model_templateargument (e.g.,--model_template deepseek) to dynamically select and apply the correct prompt format at runtime. This decouples the data from the model architecture. - Efficient Fine-Tuning: The framework fully supports LoRA and 4-bit quantization, configured via command-line arguments in the training script (
train_clone_detect.sh).
The Tuna project was adapted to be compatible with the new pipeline.
- Data Handling: The
SupervisedDatasetintrain_tuna.pywas confirmed to be compatible with the universal data format. We modified itsDataArgumentsto accept multiple input files, allowing it to consume the entire sharded dataset generated byIST. - Template System:
Tunauses its own internal, robust template system, selected via the--chat_templateargument. This system was already compatible with our goals and required no changes. - Efficient Fine-Tuning:
Tunaalso has built-in support for LoRA and QLoRA, configured via the--peftargument.
To complete the pipeline, we created a single, powerful script for inference.
Located in FABE/inference/, this script is designed to be the unified endpoint for any model trained within the FABE ecosystem.
- Model Loading: It automatically loads a base model and merges the trained LoRA adapter weights, creating a production-ready model for maximum inference speed.
- Dynamic Templates: It re-uses the same
templates.pymodule from thePROproject, ensuring that the prompt format used during inference is identical to the one used during training. - Batch Processing: The script is optimized for high-throughput inference, processing data in configurable batches.
- Usage: It is controlled via command-line arguments, requiring paths to the base model, the LoRA adapter, and the input/output files.
This project involved a significant architectural refactoring to create a robust and scalable MLOps workflow. Key achievements include:
- Decoupled Data Pipeline: We successfully separated data generation from training by creating a universal, model-agnostic dataset format.
- Refactored
PROProject: Overhauled thePROframework to use a dynamic template system, making it adaptable to any model architecture. - Adapted
TunaProject: Ensured theTunaframework was fully compatible with the new multi-file, universal dataset. - Unified Inference Script: Built a single, efficient batch inference script that can serve models from either training pipeline.
- End-to-End Workflow: Created a complete set of shell scripts (
generate_clone_data.sh,train_clone_detect.shfor bothPROandTuna) that automate the entire process from raw data to a trained model. - Bug Fixes & Verification: Conducted a thorough review of all components, identified and resolved several issues (such as argument parsing and dataset limitations), and verified the correctness of the entire pipeline.
The FABE project is now a mature, flexible, and powerful framework for state-of-the-art research in code intelligence.