AdaLoc enables secure, adaptable DNN usage control through a localized update using a small, adaptable key. It allows efficient updates to a small subset of parameters while maintaining strong performance and protecting against unauthorized access.
- Vision Tasks: Supports datasets like CIFAR-10, CIFAR-100, MNIST, FashionMNIST, Flower102, and Caltech256. Includes models such as ResNet-18, ResNet-152, DenseNet121, and ConvNeXtV2. Allows neuron selection based on criteria like Top, Random, or Bottom.
- NLP Tasks: Supports datasets such as QNLI, SST-2, and TweetEval. Compatible with BERT, RoBERTa, and DeBERTa models, with automatic logging and result storage.
-
Clone the repository:
git clone https://github.com/MLresearchAI -
Install required packages:
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 pip install -e . pip install -r requirements.txt
To train a model, run the following:
python tune_v.py --dataset cifar100 --model_name densenet121
--device: Training device (cuda:0orcpu).--dataset: Dataset for training (cifar100,cifar10,mnist,fashionmnist,flower102,caltech256).--batch_size: Default64.--num_workers: Default6.--num_epochs: Default50.--lr: Default0.001.--momentum: Default0.9.--model_name: Model architecture (resnet18,resnet152,densenet121,convnextv2).--pretrain: Use pretrained model weights (Trueby default).--num_classes: Number of output classes (100by default).--retained: Fraction of neurons to retain (0.05by default).--mode: Neuron selection mode (0for Top,1for Random,2for Bottom).
Note: For the Caltech256 dataset, download it from Kaggle.
To train a DenseNet121 model on the Caltech256 dataset:
python tune_v.py --dataset caltech256 --model_name densenet121 --pretrain --retained 0.05 --mode 0 --batch_size 64 --num_epochs 50 --lr 0.001 --momentum 0.9
Ensure the following dependencies are installed:
pip install torch transformers datasets evaluate numpy pandas
Run the script as follows:
python tune_l.py --model_name <model> --output_path <path> --mode <mode>| Argument | Type | Description |
|---|---|---|
--model_name |
string | Choose from bert-base-uncased, roberta-base, microsoft/deberta-v3-base |
--output_path |
string | Path to save the final results |
--mode |
string | Choose from smallest, largest, random |
python tune_l.py --model_name bert-base-uncased --output_path ./results --mode largestAfter running the script, the following outputs are generated:
- A CSV file containing evaluation results (
final_results.csv). - A logging directory with performance logs.
- Printed evaluation metrics like accuracy and loss.
The resulting CSV file (final_results.csv) contains:
| dataset | p | accuracy | loss |
|---|---|---|---|
| qnli | 0.05 | - | - |
| sst2 | 0.1 | - | - |
Our adaptable key is designed to support and integrate seamlessly with a wide range of model keying methods. A demonstration implementation is available in the model_keying/ directory.
cd model_keying/
# To split the target model (primary key):
python locker.py split --model <path_to_model> --ratio <key_ratio> --arch <architecture> --save ./test_output
# To restore the model:
python locker.py recover --model test_output/keyed_model.pth.tar --key test_output/key.pth.tar --arch <architecture> --save <save_path>If you find this code or dataset useful, please consider citing our paper:
@{coming soon}