[NeurIPS 2025] Practical and Effective Code Watermarking for Large Language Models
Python
7
6 commits
updated Oct 2, 2025
This repository contains the official implementation of the NeurIPS 2025 paper: "Practical and Effective Code Watermarking for Large Language Models"
This project provides a comprehensive framework for embedding and detecting watermarks in code generated by Large Language Models (LLMs), enabling provenance tracking and detection of LLM-generated code.
.
├── src/ # Source code directory
│ ├── main.py # Main application entry point
│ ├── train.py # Training module
│ ├── modelhelper.py # Model-related utilities
│ ├── datahelper.py # Data processing and handling
│ ├── utils.py # General utility functions
│ ├── sfthelper.py # SFT (Supervised Fine-Tuning) helper functions
│ └── asthelper.py # AST (Abstract Syntax Tree) processing utilities
│
├── scripts/ # Shell scripts for running experiments
│ ├── train.sh # Training script
│ └── run.sh # Evaluation script
├── lm_eval/ # Language Model evaluation directory
├── exp_utils/ # Experiment utilities
└── models/ # Model storage directory
uv pip install -r requirements.txt
Generate the training and evaluation datasets for watermarked code generation:
CUDA_VISIBLE_DEVICES=5 python src/datahelper.py
This prepares the code datasets (e.g., MBPP, HumanEval) with appropriate preprocessing for watermark training.
Train a code generation model with watermark embedding capabilities:
bash scripts/train.sh \
--model "deepseek-ai/deepseek-coder-1.3b-instruct" \
--task_name gen_mbpp \
--train_batch_size 512 \
--num_epochs 1000 \
--gpus 5 \
--augmentation false \
--alpha_distill 0.1 \
--alpha_ce 0.1 \
--alpha_switch 8.0 \
--context_width 2 \
--use_cache false
Key Parameters:
--model: Base model to fine-tune (e.g., DeepSeek Coder, OpenCoder)--task_name: Training task/dataset (e.g., gen_mbpp, humaneval)--alpha_distill, --alpha_ce, --alpha_switch: Loss weighting hyperparameters for watermark training--context_width: Context window size for watermark embedding--augmentation: Enable/disable data augmentationRun inference with the watermarked model and evaluate watermark detection:
bash scripts/run.sh \
--model "infly/OpenCoder-1.5B-Instruct" \
--task_name humanevalsynthesize-cpp \
--wm wllm \
--gpus 1 \
--code_model none \
--entropy_threshold 1.2 \
--switch_threshold 0.7 \
--seed 42 \
--delta 2.0
Key Parameters:
--model: Trained watermarked model or baseline model--task_name: Evaluation task (e.g., humanevalsynthesize-cpp, mbpp)--wm: Watermarking method (e.g., wllm)--entropy_threshold, --switch_threshold: Detection thresholds--delta: Watermark strength parameterIf you find this work useful, please cite our paper:
@inproceedings{guo2025practical,
title={Practical and Effective Code Watermarking for Large Language Models},
author={Guo, Zhimeng and Cheng, Minhao},
booktitle={The Thirty-ninth Annual Conference on Neural Information Processing Systems},
year={2025},
url={https://openreview.net/forum?id=RpE4HeuX69}
}
For questions or issues, please open an issue on GitHub or contact the authors.
[NeurIPS 2025] Practical and Effective Code Watermarking for Large Language Models
Python
7
6 commits
updated Oct 2, 2025
This repository contains the official implementation of the NeurIPS 2025 paper: "Practical and Effective Code Watermarking for Large Language Models"
This project provides a comprehensive framework for embedding and detecting watermarks in code generated by Large Language Models (LLMs), enabling provenance tracking and detection of LLM-generated code.
.
├── src/ # Source code directory
│ ├── main.py # Main application entry point
│ ├── train.py # Training module
│ ├── modelhelper.py # Model-related utilities
│ ├── datahelper.py # Data processing and handling
│ ├── utils.py # General utility functions
│ ├── sfthelper.py # SFT (Supervised Fine-Tuning) helper functions
│ └── asthelper.py # AST (Abstract Syntax Tree) processing utilities
│
├── scripts/ # Shell scripts for running experiments
│ ├── train.sh # Training script
│ └── run.sh # Evaluation script
├── lm_eval/ # Language Model evaluation directory
├── exp_utils/ # Experiment utilities
└── models/ # Model storage directory
uv pip install -r requirements.txt
Generate the training and evaluation datasets for watermarked code generation:
CUDA_VISIBLE_DEVICES=5 python src/datahelper.py
This prepares the code datasets (e.g., MBPP, HumanEval) with appropriate preprocessing for watermark training.
Train a code generation model with watermark embedding capabilities:
bash scripts/train.sh \
--model "deepseek-ai/deepseek-coder-1.3b-instruct" \
--task_name gen_mbpp \
--train_batch_size 512 \
--num_epochs 1000 \
--gpus 5 \
--augmentation false \
--alpha_distill 0.1 \
--alpha_ce 0.1 \
--alpha_switch 8.0 \
--context_width 2 \
--use_cache false
Key Parameters:
--model: Base model to fine-tune (e.g., DeepSeek Coder, OpenCoder)--task_name: Training task/dataset (e.g., gen_mbpp, humaneval)--alpha_distill, --alpha_ce, --alpha_switch: Loss weighting hyperparameters for watermark training--context_width: Context window size for watermark embedding--augmentation: Enable/disable data augmentationRun inference with the watermarked model and evaluate watermark detection:
bash scripts/run.sh \
--model "infly/OpenCoder-1.5B-Instruct" \
--task_name humanevalsynthesize-cpp \
--wm wllm \
--gpus 1 \
--code_model none \
--entropy_threshold 1.2 \
--switch_threshold 0.7 \
--seed 42 \
--delta 2.0
Key Parameters:
--model: Trained watermarked model or baseline model--task_name: Evaluation task (e.g., humanevalsynthesize-cpp, mbpp)--wm: Watermarking method (e.g., wllm)--entropy_threshold, --switch_threshold: Detection thresholds--delta: Watermark strength parameterIf you find this work useful, please cite our paper:
@inproceedings{guo2025practical,
title={Practical and Effective Code Watermarking for Large Language Models},
author={Guo, Zhimeng and Cheng, Minhao},
booktitle={The Thirty-ninth Annual Conference on Neural Information Processing Systems},
year={2025},
url={https://openreview.net/forum?id=RpE4HeuX69}
}
For questions or issues, please open an issue on GitHub or contact the authors.