Code Monkey home page Code Monkey logo

dp-transformers's Introduction

dp-transformers

โš ๏ธ This repo is intended for research projects and prototypes. While we try to provide tests for all the functionality, the repo has not (yet) undergone the detailed review process that is necessary for deploying a system of critical nature such as privacy.

Introduction

See dp-transformers for a brief introduction to our repository.

Installation

For installing the dp-transformers package, you can just type

pip install .

Examples

See ./examples for end to end examples of how to use the library.

A basic example can be found in examples/nlg-reddit/sample-level-dp/fine-tune-dp.py. First, create an Anaconda environment by doing conda env create -f examples/nlg-reddit/sample-level-dp/environment.yml. Then, you can run the example using the following command (here we assume there are 16 GPUs in the machine, and thus set --nproc_per_node 16):

python -m torch.distributed.run --nproc_per_node 16 examples/nlg-reddit/sample-level-dp/fine-tune-dp.py \
--output_dir scratch \
--model_name gpt2 \
--sequence_len 128 \
--per_device_train_batch_size 32 \
--gradient_accumulation_steps 2 \
--evaluation_strategy steps \
--eval_steps 45 \
--log_level info \
--per_device_eval_batch_size 64 \
--eval_accumulation_steps 1 \
--seed 42 \
--target_epsilon 8 \
--per_sample_max_grad_norm 1.0 \
--prediction_loss_only \
--weight_decay 0.01 \
--remove_unused_columns False \
--num_train_epochs 3 \
--logging_steps 5 \
--max_grad_norm 0 \
--lr_scheduler_type constant \
--learning_rate 1e-4 \
--disable_tqdm True \
--dataloader_num_workers 2

๐Ÿค— Transformers with Opacus

Trainer

Huggingface's trainer provides callback hooks which we can use to make sure the required methods in the privacy engine are called.

You can use the callback as demonstrated in the example below

privacy_engine = opacus.PrivacyEngine(module=model, ...)

# No need to attach the privacy engine to the optimizer. The callback will automatically attach the optimizer.

trainer = transformers.Trainer(
    model = model,
    [...],
    callbacks = [dp_transformers.PrivacyEngineCallback(privacy_engine)]  # <-- Add this line to make sure the privacy engine is used in the trainer
    [...]
)

Data Collation

๐Ÿค— Transformers library often provides sensible default arguments. For example, when no position_ids are provided, the library automatically will use incrementing integers. The way this is implemented is by first creating a tensor of shape [1, sequence_length] filled with increasing integers. During a second step that tensor is replicated for the whole batch. However, the replication is part of the computational graph and hence Opacus cannot infer the batch size from this input tensor.

We have therefore implemented a custom data collator (see dp_transformers.DataCollatorForPrivateCausalLanguageModeling) which automatically creates the position_ids input tensor by using torch.repeat. This works with opacus since the position_ids tensor appears as batch size different inputs in the computation graph.

GPT2

The ๐Ÿค— Transformers implementation for GPT2 uses a custom layer type namely Conv1D. It is not quite clear why this was introduced since it is essentially a regular linear layer. This causes problems with Opacus though since it is not sure how to apply the backward hooks for this layer.

In this repo we provide an implementation for handling this type of layer. See dp_transformers.grad_sample.transformers.conv_1d

All necessary grad samplers can be registered by merely importing conv_1d before the model training. See the Known Issues section below for more details.

General tips for DP training

In this section, we collect a few helpful strategies for training models with DP. Also Opacus's FAQs have a few tips on how to get started with DP training (see Opacus FAQ)

Hyper-parameters

Larger batch sizes help DP training. As a general rule, try starting with $\sqrt{|D|}$ where $D$ is the training dataset. Since Opacus increases memory consumption significantly, this is only possible using gradient accumulation.

We have found a surprisingly small dependence on the clipping norm. As a general rule of thumb start with a clipping parameter of 0.1

Fine-tuning the model longer is also helpful.

Deploying DP trained models

Pay attention which pseudo random number generator (PRNG) was used. Pytorch's default (Mersenne Twister) might be attackable. See Opacus FAQ Make sure to use a better PRNG before deploying models.

Known issues

Register custom grad samplers late in the training process

When registering custom grad sampler like dp_transformers.grad_sample.transformers.conv_1d, functions are added to a global dictionary that Opacus handles. This global dictionary is used to establish whether models are compatible with Opacus and how to handle the per-sample gradient computation. All grad samplers need to be registered as early as possible in the training process. Definitely, before the model is wrapped with GradSampleModule.

How to Cite

@misc{dp-transformers,
  author        = {Lukas Wutschitz and Huseyin A. Inan and Andre Manoel},
  title         = {dp-transformers: Training transformer models with differential privacy},
  year          = {2022},
  month         = {August},
  howpublished  = {\url{https://www.microsoft.com/en-us/research/project/dp-transformers}}
}

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

For any other questions, feel free to open an issue on GitHub.

dp-transformers's People

Contributors

amanoel avatar donebydan avatar huseyinatahaninan avatar wulu473 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dp-transformers's Issues

Using dp-transformers models for inference

I am trying to load a fine-tuned model from dp-transformers for inference but am receiving the error below, which appears to be due to overloading the default Trainer model with the GradSampleModule from Opacus, which is not backwards compatible with the HF model's generate functions. Can you share any feedback or examples about how to prompt the DP models for text generation?

Thanks in advance.

Example code:

# Save the model to the disk
trainer.save_model(output_dir=train_args.output_dir)

# Generation
prompt_text = "The answer to the great question of Life, the Universe and Everything is"
encoded_prompt = tokenizer.encode(prompt_text, add_special_tokens=False, return_tensors="pt")
generated_sequences = trainer.model.generate(encoded_prompt, max_length=100, temperature=1.0)

# Decode it
generated_sequences = generated_sequences[0].tolist()
text = tokenizer.decode(generated_sequences, clean_up_tokenization_spaces=True)
print(text)

Error:

[INFO|trainer.py:1786] 2023-06-26 17:13:28,916 >> ***** Running training *****
[INFO|trainer.py:1787] 2023-06-26 17:13:28,916 >>   Num examples = 980
[INFO|trainer.py:1788] 2023-06-26 17:13:28,916 >>   Num Epochs = 3
[INFO|trainer.py:1789] 2023-06-26 17:13:28,916 >>   Instantaneous batch size per device = 64
[INFO|trainer.py:1790] 2023-06-26 17:13:28,916 >>   Total train batch size (w. parallel, distributed & accumulation) = 64
[INFO|trainer.py:1791] 2023-06-26 17:13:28,916 >>   Gradient Accumulation steps = 1
[INFO|trainer.py:1792] 2023-06-26 17:13:28,916 >>   Total optimization steps = 45
[INFO|trainer.py:1793] 2023-06-26 17:13:28,917 >>   Number of trainable parameters = 147,456

...

{'loss': 3.9738, 'learning_rate': 0.0003, 'epoch': 3.0}
[INFO|trainer.py:3200] 2023-06-26 17:14:16,735 >> ***** Running Evaluation *****
[INFO|trainer.py:3202] 2023-06-26 17:14:16,735 >>   Num examples = 20
[INFO|trainer.py:3205] 2023-06-26 17:14:16,735 >>   Batch size = 64
[WARNING|logging.py:280] 2023-06-26 17:14:16,789 >> You're using a GPT2TokenizerFast tokenizer. Please note that with a fast tokenizer, using the `__call__` method is faster than using a method to encode the text followed by a call to the `pad` method to get a padded encoding.
{'eval_runtime': 0.1748, 'eval_samples_per_second': 114.414, 'eval_steps_per_second': 5.721, 'epoch': 3.0}
[INFO|trainer.py:2053] 2023-06-26 17:14:17,119 >> 

Training completed. Do not forget to share your model on huggingface.co/models =)

{'train_runtime': 48.203, 'train_samples_per_second': 60.992, 'train_steps_per_second': 0.934, 'train_loss': 4.016973029242622, 'epoch': 3.0}
{'final_epsilon_prv': 7.815436928174181, 'final_epsilon_rdp': 9.690711958418493, 'epoch': 3.0}
[INFO|trainer.py:2926] 2023-06-26 17:14:17,324 >> Saving model checkpoint to scratch
[INFO|trainer.py:2940] 2023-06-26 17:14:17,326 >> Trainer.model is not a `PreTrainedModel`, only saving its state dict.
Traceback (most recent call last):
  File "/home/redlined/dp-transformers/fine-tune-dp.py", line 192, in <module>
    main(Arguments(train=train_args, privacy=privacy_args, model=model_args, dataset=dataset_args))
  File "/home/redlined/dp-transformers/fine-tune-dp.py", line 183, in main
    generated_sequences = trainer.model.generate(encoded_prompt, max_length=100, temperature=1.0)
  File "/opt/conda/envs/dp/lib/python3.10/site-packages/opacus/grad_sample/gsm_base.py", line 77, in __getattr__
    raise e
  File "/opt/conda/envs/dp/lib/python3.10/site-packages/opacus/grad_sample/gsm_base.py", line 72, in __getattr__
    return super().__getattr__(item)
  File "/opt/conda/envs/dp/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1614, in __getattr__
    raise AttributeError("'{}' object has no attribute '{}'".format(
AttributeError: 'GradSampleModule' object has no attribute 'generate'

RuntimeError: Default process group has not been initialized

Hi there,
I'm trying to privatize a GPT-2 model with a dataset of my own. For that I'm using the fine-tune-dp.py script but with small adjustments regarding the dataset.

dataset = datasets.load_dataset("text", data_files=train_args.train_file)

tokenizer = transformers.AutoTokenizer.from_pretrained(args.model.model_name)
tokenizer.pad_token = -100 # Set a dummy pad token we don't use it anyway

with train_args.main_process_first(desc="tokenizing dataset"):
    dataset = dataset.map(
        lambda batch: tokenizer(batch['text'], padding="max_length", truncation=True, max_length=args.model.sequence_len),
        batched=True, num_proc=8, desc="tokenizing dataset", remove_columns=dataset.column_names['train']
    )

I think this all works fine, however I get a RuntimeError which tells me that the default process group has not been initialized.
Can someone tell me what to do?

Thanks very much in advance!

This is output of the script:

[INFO|configuration_utils.py:588]` 2022-08-18 10:18:22,287 >> loading configuration file https://huggingface.co/gpt2/resolve/main/config.json from cache at /.cache/huggingface/transformers/fc674cd6907b4c9e933cb42d67662436b89fa9540a1f40d7c919d0109289ad01.7d2e0efa5ca20cef4fb199382111e9d3ad96fd77b849e1d4bed13a66e1336f51
[INFO|configuration_utils.py:625] 2022-08-18 10:18:22,291 >> Model config GPT2Config {
"activation_function": "gelu_new",
"architectures": [
"GPT2LMHeadModel"
],
"attn_pdrop": 0.1,
"bos_token_id": 50256,
"embd_pdrop": 0.1,
"eos_token_id": 50256,
"initializer_range": 0.02,
"layer_norm_epsilon": 1e-05,
"model_type": "gpt2",
"n_ctx": 1024,
"n_embd": 768,
"n_head": 12,
"n_inner": null,
"n_layer": 12,
"n_positions": 1024,
"reorder_and_upcast_attn": false,
"resid_pdrop": 0.1,
"scale_attn_by_inverse_layer_idx": false,
"scale_attn_weights": true,
"summary_activation": null,
"summary_first_dropout": 0.1,
"summary_proj_to_labels": true,
"summary_type": "cls_index",
"summary_use_proj": true,
"task_specific_params": {
"text-generation": {
"do_sample": true,
"max_length": 50
}
},
"transformers_version": "4.12.2",
"use_cache": true,
"vocab_size": 50257
}

[INFO|modeling_utils.py:1340] 2022-08-18 10:18:23,257 >> loading weights file https://huggingface.co/gpt2/resolve/main/pytorch_model.bin from cache at /.cache/huggingface/transformers/752929ace039baa8ef70fe21cdf9ab9445773d20e733cf693d667982e210837e.323c769945a351daa25546176f8208b3004b6f563438a7603e7932bae9025925
[INFO|modeling_utils.py:1607] 2022-08-18 10:18:25,864 >> All model checkpoint weights were used when initializing GPT2LMHeadModel.

[INFO|modeling_utils.py:1615] 2022-08-18 10:18:25,866 >> All the weights of GPT2LMHeadModel were initialized from the model checkpoint at gpt2.
If your task is similar to the task the model of the checkpoint was trained on, you can already use GPT2LMHeadModel for predictions without further training.
100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 1/1 [00:01<00:00, 1.15s/it]
[INFO|tokenization_auto.py:341] 2022-08-18 10:18:57,004 >> Could not locate the tokenizer configuration file, will try to use the model config instead.
[INFO|configuration_utils.py:588] 2022-08-18 10:18:57,431 >> loading configuration file https://huggingface.co/gpt2/resolve/main/config.json from cache at /.cache/huggingface/transformers/fc674cd6907b4c9e933cb42d67662436b89fa9540a1f40d7c919d0109289ad01.7d2e0efa5ca20cef4fb199382111e9d3ad96fd77b849e1d4bed13a66e1336f51
[INFO|configuration_utils.py:625] 2022-08-18 10:18:57,435 >> Model config GPT2Config {
"activation_function": "gelu_new",
"architectures": [
"GPT2LMHeadModel"
],
"attn_pdrop": 0.1,
"bos_token_id": 50256,
"embd_pdrop": 0.1,
"eos_token_id": 50256,
"initializer_range": 0.02,
"layer_norm_epsilon": 1e-05,
"model_type": "gpt2",
"n_ctx": 1024,
"n_embd": 768,
"n_head": 12,
"n_inner": null,
"n_layer": 12,
"n_positions": 1024,
"reorder_and_upcast_attn": false,
"resid_pdrop": 0.1,
"scale_attn_by_inverse_layer_idx": false,
"scale_attn_weights": true,
"summary_activation": null,
"summary_first_dropout": 0.1,
"summary_proj_to_labels": true,
"summary_type": "cls_index",
"summary_use_proj": true,
"task_specific_params": {
"text-generation": {
"do_sample": true,
"max_length": 50
}
},
"transformers_version": "4.12.2",
"use_cache": true,
"vocab_size": 50257
}

[INFO|tokenization_utils_base.py:1742] 2022-08-18 10:19:00,486 >> loading file https://huggingface.co/gpt2/resolve/main/vocab.json from cache at /.cache/huggingface/transformers/684fe667923972fb57f6b4dcb61a3c92763ad89882f3da5da9866baf14f2d60f.c7ed1f96aac49e745788faa77ba0a26a392643a50bb388b9c04ff469e555241f
[INFO|tokenization_utils_base.py:1742] 2022-08-18 10:19:00,488 >> loading file https://huggingface.co/gpt2/resolve/main/merges.txt from cache at /.cache/huggingface/transformers/c0c761a63004025aeadd530c4c27b860ec4ecbe8a00531233de21d865a402598.5d12962c5ee615a4c803841266e9c3be9a691a924f72d395d3a6c6c81157788b
[INFO|tokenization_utils_base.py:1742] 2022-08-18 10:19:00,490 >> loading file https://huggingface.co/gpt2/resolve/main/tokenizer.json from cache at /.cache/huggingface/transformers/16a2f78023c8dc511294f0c97b5e10fde3ef9889ad6d11ffaa2a00714e73926e.cf2d0ecb83b6df91b3dbb53f1d1e4c311578bfd3aa0e04934215a49bf9898df0
[INFO|tokenization_utils_base.py:1742] 2022-08-18 10:19:00,491 >> loading file https://huggingface.co/gpt2/resolve/main/added_tokens.json from cache at None
[INFO|tokenization_utils_base.py:1742] 2022-08-18 10:19:00,493 >> loading file https://huggingface.co/gpt2/resolve/main/special_tokens_map.json from cache at None
[INFO|tokenization_utils_base.py:1742] 2022-08-18 10:19:00,494 >> loading file https://huggingface.co/gpt2/resolve/main/tokenizer_config.json from cache at None
[INFO|configuration_utils.py:588] 2022-08-18 10:19:00,937 >> loading configuration file https://huggingface.co/gpt2/resolve/main/config.json from cache at /.cache/huggingface/transformers/fc674cd6907b4c9e933cb42d67662436b89fa9540a1f40d7c919d0109289ad01.7d2e0efa5ca20cef4fb199382111e9d3ad96fd77b849e1d4bed13a66e1336f51
[INFO|configuration_utils.py:625] 2022-08-18 10:19:00,941 >> Model config GPT2Config {
"activation_function": "gelu_new",
"architectures": [
"GPT2LMHeadModel"
],
"attn_pdrop": 0.1,
"bos_token_id": 50256,
"embd_pdrop": 0.1,
"eos_token_id": 50256,
"initializer_range": 0.02,
"layer_norm_epsilon": 1e-05,
"model_type": "gpt2",
"n_ctx": 1024,
"n_embd": 768,
"n_head": 12,
"n_inner": null,
"n_layer": 12,
"n_positions": 1024,
"reorder_and_upcast_attn": false,
"resid_pdrop": 0.1,
"scale_attn_by_inverse_layer_idx": false,
"scale_attn_weights": true,
"summary_activation": null,
"summary_first_dropout": 0.1,
"summary_proj_to_labels": true,
"summary_type": "cls_index",
"summary_use_proj": true,
"task_specific_params": {
"text-generation": {
"do_sample": true,
"max_length": 50
}
},
"transformers_version": "4.12.2",
"use_cache": true,
"vocab_size": 50257
}

tokenizing dataset #3: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 456/456 [04:02<00:00, 1.88ba/s]
tokenizing dataset #4: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 456/456 [04:07<00:00, 1.85ba/s]
tokenizing dataset #6: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 456/456 [04:06<00:00, 1.85ba/s]
tokenizing dataset #5: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 456/456 [04:07<00:00, 1.84ba/s]
tokenizing dataset #1: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 456/456 [04:10<00:00, 1.82ba/s]
tokenizing dataset #7: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 456/456 [04:10<00:00, 1.82ba/s]
tokenizing dataset #0: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 456/456 [04:12<00:00, 1.80ba/s]
tokenizing dataset #2: 100%|โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆ| 456/456 [04:12<00:00, 1.80ba/s]
Traceback (most recent call last):โ–ˆโ–ˆโ–ˆโ–‰| 451/456 [04:12<00:01, 4.01ba/s]
File "/fplm/dp-transformers/fine-tune-dp.py", line 179, in
main(Arguments(train=train_args, privacy=privacy_args, model=model_args))
File "/fplm/dp-transformers/fine-tune-dp.py", line 120, in main
model = dp_transformers.dp_utils.DifferentiallyPrivateDistributedDataParallel(model)
File "/fplm/miniconda3/env/lib/python3.9/site-packages/opacus/layers/dp_ddp.py", line 25, in init
torch.distributed.broadcast(p.data, 0)
File "/fplm/miniconda3/env/lib/python3.9/site-packages/torch/distributed/distributed_c10d.py", line 1075, in broadcast
default_pg = _get_default_group()
File "/fplm/miniconda3/env/lib/python3.9/site-packages/torch/distributed/distributed_c10d.py", line 358, in _get_default_group
raise RuntimeError("Default process group has not been initialized, "
RuntimeError: Default process group has not been initialized, please make sure to call init_process_group.``

Failed to run the example

I ran the example given

import os
os.environ["WANDB_DISABLED"] = "true"
!python examples/nlg-reddit/sample-level-dp/fine-tune-dp.py \
--output_dir scratch \
--model_name sshleifer/tiny-gpt2 \
--sequence_len 128 \
--per_device_train_batch_size 16 \
--gradient_accumulation_steps 2 \
--evaluation_strategy steps \
--eval_steps 45 \
--log_level info \
--per_device_eval_batch_size 32 \
--eval_accumulation_steps 1 \
--seed 42 \
--target_epsilon 8 \
--per_sample_max_grad_norm 1.0 \
--prediction_loss_only \
--weight_decay 0.01 \
--remove_unused_columns False \
--num_train_epochs 3 \
--logging_steps 5 \
--max_grad_norm 0 \
--lr_scheduler_type constant \
--learning_rate 1e-4 \
--disable_tqdm True \
--dataloader_num_workers 2 

but got these

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Traceback (most recent call last) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ /kaggle/working/dp-transformers/examples/nlg-reddit/sample-level-dp/fine-tun โ”‚
โ”‚ e-dp.py:137 in <module>                                                      โ”‚
โ”‚                                                                              โ”‚
โ”‚   134 if __name__ == "__main__":                                             โ”‚
โ”‚   135 โ”‚   arg_parser = transformers.HfArgumentParser((dp_transformers.Traini โ”‚
โ”‚   136 โ”‚   train_args, privacy_args, model_args = arg_parser.parse_args_into_ โ”‚
โ”‚ โฑ 137 โ”‚   main(Arguments(train=train_args, privacy=privacy_args, model=model โ”‚
โ”‚   138                                                                        โ”‚
โ”‚                                                                              โ”‚
โ”‚ /kaggle/working/dp-transformers/examples/nlg-reddit/sample-level-dp/fine-tun โ”‚
โ”‚ e-dp.py:125 in main                                                          โ”‚
โ”‚                                                                              โ”‚
โ”‚   122 โ”‚   )                                                                  โ”‚
โ”‚   123 โ”‚                                                                      โ”‚
โ”‚   124 โ”‚   try:                                                               โ”‚
โ”‚ โฑ 125 โ”‚   โ”‚   trainer.train()                                                โ”‚
โ”‚   126 โ”‚   finally:                                                           โ”‚
โ”‚   127 โ”‚   โ”‚   eps_prv = trainer.get_prv_epsilon()                            โ”‚
โ”‚   128 โ”‚   โ”‚   eps_rdp = trainer.get_rdp_epsilon()                            โ”‚
โ”‚                                                                              โ”‚
โ”‚ /opt/conda/lib/python3.10/site-packages/transformers/trainer.py:1645 in      โ”‚
โ”‚ train                                                                        โ”‚
โ”‚                                                                              โ”‚
โ”‚   1642 โ”‚   โ”‚   inner_training_loop = find_executable_batch_size(             โ”‚
โ”‚   1643 โ”‚   โ”‚   โ”‚   self._inner_training_loop, self._train_batch_size, args.a โ”‚
โ”‚   1644 โ”‚   โ”‚   )                                                             โ”‚
โ”‚ โฑ 1645 โ”‚   โ”‚   return inner_training_loop(                                   โ”‚
โ”‚   1646 โ”‚   โ”‚   โ”‚   args=args,                                                โ”‚
โ”‚   1647 โ”‚   โ”‚   โ”‚   resume_from_checkpoint=resume_from_checkpoint,            โ”‚
โ”‚   1648 โ”‚   โ”‚   โ”‚   trial=trial,                                              โ”‚
โ”‚                                                                              โ”‚
โ”‚ /opt/conda/lib/python3.10/site-packages/transformers/trainer.py:1938 in      โ”‚
โ”‚ _inner_training_loop                                                         โ”‚
โ”‚                                                                              โ”‚
โ”‚   1935 โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   self.control = self.callback_handler.on_step_begi โ”‚
โ”‚   1936 โ”‚   โ”‚   โ”‚   โ”‚                                                         โ”‚
โ”‚   1937 โ”‚   โ”‚   โ”‚   โ”‚   with self.accelerator.accumulate(model):              โ”‚
โ”‚ โฑ 1938 โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   tr_loss_step = self.training_step(model, inputs)  โ”‚
โ”‚   1939 โ”‚   โ”‚   โ”‚   โ”‚                                                         โ”‚
โ”‚   1940 โ”‚   โ”‚   โ”‚   โ”‚   if (                                                  โ”‚
โ”‚   1941 โ”‚   โ”‚   โ”‚   โ”‚   โ”‚   args.logging_nan_inf_filter                       โ”‚
โ”‚                                                                              โ”‚
โ”‚ /opt/conda/lib/python3.10/site-packages/dp_transformers/dp_utils.py:263 in   โ”‚
โ”‚ training_step                                                                โ”‚
โ”‚                                                                              โ”‚
โ”‚   260 โ”‚   โ”‚   โ”‚   raise NotImplementedError("DP currently doesn't support th โ”‚
โ”‚   261 โ”‚   โ”‚   elif self.use_apex:                                            โ”‚
โ”‚   262 โ”‚   โ”‚   โ”‚   raise NotImplementedError("DP currently doesn't support th โ”‚
โ”‚ โฑ 263 โ”‚   โ”‚   elif self.deepspeed:                                           โ”‚
โ”‚   264 โ”‚   โ”‚   โ”‚   raise NotImplementedError("DP currently doesn't support th โ”‚
โ”‚   265 โ”‚   โ”‚   else:                                                          โ”‚
โ”‚   266 โ”‚   โ”‚   โ”‚   loss.backward()                                            โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
AttributeError: 'OpacusDPTrainer' object has no attribute 'deepspeed'

here is my environment

Package                                Version              Editable project location
-------------------------------------- -------------------- -------------------------
absl-py                                1.4.0
accelerate                             0.20.3
access                                 1.1.9
affine                                 2.4.0
aiobotocore                            2.5.0
aiofiles                               22.1.0
aiohttp                                3.8.4
aiohttp-cors                           0.7.0
aioitertools                           0.11.0
aiorwlock                              1.3.0
aiosignal                              1.3.1
aiosqlite                              0.19.0
albumentations                         1.3.1
alembic                                1.11.1
altair                                 5.0.1
annoy                                  1.17.2
ansiwrap                               0.8.4
anyio                                  3.6.2
apache-beam                            2.46.0
aplus                                  0.11.0
appdirs                                1.4.4
argon2-cffi                            21.3.0
argon2-cffi-bindings                   21.2.0
array-record                           0.2.0
arrow                                  1.2.3
arviz                                  0.12.1
astroid                                2.15.5
astropy                                5.3
asttokens                              2.2.1
astunparse                             1.6.3
async-timeout                          4.0.2
atpublic                               3.1.2
attrs                                  23.1.0
audioread                              3.0.0
autopep8                               2.0.2
Babel                                  2.12.1
backcall                               0.2.0
backoff                                2.2.1
backports.functools-lru-cache          1.6.4
bayesian-optimization                  1.4.3
bayespy                                0.5.26
beatrix-jupyterlab                     2023.58.190319
beautifulsoup4                         4.12.2
bidict                                 0.22.1
biopython                              1.81
blake3                                 0.2.1
bleach                                 6.0.0
blessed                                1.20.0
blinker                                1.6.2
blis                                   0.7.9
blosc2                                 2.0.0
bokeh                                  3.1.1
boltons                                23.0.0
Boruta                                 0.3
boto3                                  1.26.100
botocore                               1.29.76
bq-helper                              0.4.1                /src/bq-helper
bqplot                                 0.12.39
branca                                 0.6.0
brewer2mpl                             1.4.1
brotlipy                               0.7.0
cached-property                        1.5.2
cachetools                             4.2.4
Cartopy                                0.21.1
catalogue                              2.0.8
catalyst                               22.4
catboost                               1.2
category-encoders                      2.6.1
certifi                                2023.5.7
cesium                                 0.12.1
cffi                                   1.15.1
cftime                                 1.6.2
charset-normalizer                     2.1.1
chex                                   0.1.7
cleverhans                             4.0.0
click                                  8.1.3
click-plugins                          1.1.1
cligj                                  0.7.2
cloud-tpu-client                       0.10
cloud-tpu-profiler                     2.4.0
cloudpickle                            2.2.1
cmaes                                  0.9.1
cmdstanpy                              1.1.0
cmudict                                1.0.13
colorama                               0.4.6
colorcet                               3.0.1
colorful                               0.5.5
colorlog                               6.7.0
colorlover                             0.3.0
comm                                   0.1.3
commonmark                             0.9.1
conda                                  23.3.1
conda-content-trust                    0+unknown
conda-package-handling                 2.0.2
conda_package_streaming                0.7.0
confection                             0.0.4
contextily                             1.3.0
contourpy                              1.0.7
convertdate                            2.4.0
crcmod                                 1.7
cryptography                           40.0.2
cubinlinker                            0.3.0
cuda-python                            11.8.2
cudf                                   23.6.0
cufflinks                              0.17.3
cuml                                   23.6.0
cupy                                   12.0.0
CVXcanon                               0.1.2
cycler                                 0.11.0
cymem                                  2.0.7
cysignals                              1.11.2
Cython                                 0.29.34
cytoolz                                0.12.0
daal                                   2023.1.1
daal4py                                2023.1.1
dask                                   2023.6.0
dask-cuda                              23.6.0
dask-cudf                              23.6.0
dataclasses                            0.8
dataclasses-json                       0.5.8
datasets                               2.1.0
datashader                             0.15.0
datashape                              0.5.2
datatile                               1.0.3
db-dtypes                              1.1.1
deap                                   1.3.3
debugpy                                1.6.7
decorator                              5.1.1
deepspeed                              0.9.5
defusedxml                             0.7.1
Delorean                               1.0.0
deprecat                               2.1.1
Deprecated                             1.2.13
deprecation                            2.1.0
descartes                              1.1.0
dill                                   0.3.6
dipy                                   1.7.0
distlib                                0.3.6
distributed                            2023.3.2.1
dm-tree                                0.1.8
docker                                 6.1.1
docker-pycreds                         0.4.0
docopt                                 0.6.2
docstring-parser                       0.15
docstring-to-markdown                  0.12
docutils                               0.20.1
dp-transformers                        1.0.0
earthengine-api                        0.1.356
easydict                               1.10
easyocr                                1.7.0
ecos                                   2.0.12
eli5                                   0.13.0
emoji                                  2.5.0
en-core-web-lg                         3.5.0
en-core-web-sm                         3.5.0
entrypoints                            0.4
ephem                                  4.1.4
esda                                   2.4.3
essentia                               2.1b6.dev1034
et-xmlfile                             1.1.0
etils                                  1.2.0
exceptiongroup                         1.1.1
executing                              1.2.0
explainable-ai-sdk                     1.3.3
fastai                                 2.7.12
fastapi                                0.95.1
fastavro                               1.7.4
fastcore                               1.5.29
fastdownload                           0.0.7
fasteners                              0.18
fastjsonschema                         2.16.3
fastprogress                           1.0.3
fastrlock                              0.8
fasttext                               0.9.2
fbpca                                  1.0
feather-format                         0.4.1
featuretools                           1.26.0
filelock                               3.12.0
Fiona                                  1.9.4.post1
fire                                   0.5.0
fitter                                 1.5.2
flake8                                 6.0.0
flashtext                              2.7
Flask                                  2.3.2
flatbuffers                            23.3.3
flax                                   0.6.10
flit_core                              3.8.0
folium                                 0.14.0
fonttools                              4.39.3
fqdn                                   1.5.1
frozendict                             2.3.8
frozenlist                             1.3.3
fsspec                                 2023.6.0
functorch                              0.2.1
funcy                                  2.0
fury                                   0.9.0
future                                 0.18.3
fuzzywuzzy                             0.18.0
gast                                   0.4.0
gatspy                                 0.3
gcsfs                                  2023.5.0
gensim                                 4.3.1
geographiclib                          2.0
Geohash                                1.0
geojson                                3.0.1
geopandas                              0.13.2
geoplot                                0.5.1
geopy                                  2.3.0
geoviews                               1.10.0
ggplot                                 0.11.5
giddy                                  2.3.4
gitdb                                  4.0.10
GitPython                              3.1.31
google-api-core                        1.33.2
google-api-python-client               2.88.0
google-apitools                        0.5.31
google-auth                            2.17.3
google-auth-httplib2                   0.1.0
google-auth-oauthlib                   1.0.0
google-cloud-aiplatform                0.6.0a1
google-cloud-artifact-registry         1.8.1
google-cloud-automl                    1.0.1
google-cloud-bigquery                  2.34.4
google-cloud-bigtable                  1.7.3
google-cloud-core                      2.3.2
google-cloud-datastore                 2.15.2
google-cloud-dlp                       3.12.1
google-cloud-language                  2.6.1
google-cloud-monitoring                2.14.2
google-cloud-pubsub                    2.16.1
google-cloud-pubsublite                1.8.1
google-cloud-recommendations-ai        0.7.1
google-cloud-resource-manager          1.10.0
google-cloud-spanner                   3.33.0
google-cloud-storage                   1.44.0
google-cloud-translate                 3.8.4
google-cloud-videointelligence         2.8.3
google-cloud-vision                    2.8.0
google-crc32c                          1.5.0
google-pasta                           0.2.0
google-resumable-media                 2.5.0
googleapis-common-protos               1.57.1
gplearn                                0.4.2
gpustat                                1.0.0
gpxpy                                  1.5.0
graphviz                               0.20.1
greenlet                               2.0.2
grpc-google-iam-v1                     0.12.6
grpcio                                 1.51.1
grpcio-status                          1.48.1
gviz-api                               1.10.0
gym                                    0.26.2
gym-notices                            0.0.8
Gymnasium                              0.26.3
gymnasium-notices                      0.0.1
h11                                    0.14.0
h2o                                    3.40.0.4
h5py                                   3.8.0
haversine                              2.8.0
hdfs                                   2.7.0
hep-ml                                 0.7.2
hijri-converter                        2.3.1
hjson                                  3.1.0
hmmlearn                               0.3.0
holidays                               0.24
holoviews                              1.16.2
hpsklearn                              0.1.0
html5lib                               1.1
htmlmin                                0.1.12
httplib2                               0.21.0
httptools                              0.5.0
huggingface-hub                        0.15.1
humanize                               4.6.0
hunspell                               0.5.5
husl                                   4.0.3
hydra-slayer                           0.4.1
hyperopt                               0.2.7
hypertools                             0.8.0
ibis-framework                         5.1.0
idna                                   3.4
igraph                                 0.10.4
imagecodecs                            2023.3.16
ImageHash                              4.3.1
imageio                                2.28.1
imbalanced-learn                       0.10.1
imgaug                                 0.4.0
implicit                               0.5.2
importlib-metadata                     5.2.0
importlib-resources                    5.12.0
inequality                             1.0.0
iniconfig                              2.0.0
ipydatawidgets                         4.3.4
ipykernel                              6.23.0
ipyleaflet                             0.17.3
ipympl                                 0.7.0
ipython                                8.13.2
ipython-genutils                       0.2.0
ipython-sql                            0.5.0
ipyvolume                              0.6.3
ipyvue                                 1.9.1
ipyvuetify                             1.8.10
ipywebrtc                              0.6.0
ipywidgets                             7.7.1
isoduration                            20.11.0
isort                                  5.12.0
isoweek                                1.3.3
itsdangerous                           2.1.2
Janome                                 0.4.2
jaraco.classes                         3.2.3
jax                                    0.4.8
jaxlib                                 0.4.7+cuda11.cudnn86
jedi                                   0.18.2
jeepney                                0.8.0
jieba                                  0.42.1
Jinja2                                 3.1.2
jmespath                               1.0.1
joblib                                 1.2.0
json5                                  0.9.11
jsonpatch                              1.32
jsonpointer                            2.0
jsonschema                             4.17.3
jupyter_client                         7.4.9
jupyter-console                        6.6.3
jupyter_core                           5.3.0
jupyter-events                         0.6.3
jupyter-http-over-ws                   0.0.8
jupyter-lsp                            1.5.1
jupyter_server                         2.5.0
jupyter_server_fileid                  0.9.0
jupyter-server-mathjax                 0.2.6
jupyter_server_proxy                   4.0.0
jupyter_server_terminals               0.4.4
jupyter_server_ydoc                    0.8.0
jupyter-ydoc                           0.2.4
jupyterlab                             3.6.4
jupyterlab-git                         0.41.0
jupyterlab-lsp                         4.2.0
jupyterlab-pygments                    0.2.2
jupyterlab_server                      2.22.1
jupyterlab-widgets                     3.0.7
jupytext                               1.14.5
kaggle                                 1.5.13
kaggle-environments                    1.12.0
keras                                  2.12.0
keras-tuner                            1.3.5
keyring                                23.13.1
keyrings.google-artifactregistry-auth  1.1.2
kfp                                    1.8.21
kfp-pipeline-spec                      0.1.16
kfp-server-api                         1.8.5
kiwisolver                             1.4.4
kmapper                                2.0.1
kmodes                                 0.12.2
korean-lunar-calendar                  0.3.1
kornia                                 0.6.12
kt-legacy                              1.0.5
kubernetes                             25.3.0
langcodes                              3.3.0
langid                                 1.1.6
lazy_loader                            0.2
lazy-object-proxy                      1.9.0
learntools                             0.3.4
leven                                  1.0.4
Levenshtein                            0.21.1
libclang                               16.0.0
libmambapy                             1.4.2
libpysal                               4.7.0
librosa                                0.10.0.post2
lightgbm                               3.3.2
lightning-utilities                    0.8.0
lime                                   0.2.0.1
line-profiler                          4.0.3
linkify-it-py                          2.0.2
llvmlite                               0.40.0
lml                                    0.1.0
locket                                 1.0.0
LunarCalendar                          0.0.9
lxml                                   4.9.2
lz4                                    4.3.2
Mako                                   1.2.4
mamba                                  1.4.2
mapclassify                            2.5.0
marisa-trie                            0.8.0
Markdown                               3.4.3
markdown-it-py                         2.2.0
markovify                              0.9.4
MarkupSafe                             2.1.2
marshmallow                            3.19.0
marshmallow-enum                       1.5.1
matplotlib                             3.6.3
matplotlib-inline                      0.1.6
matplotlib-venn                        0.11.9
mccabe                                 0.7.0
mdit-py-plugins                        0.3.5
mdurl                                  0.1.2
memory-profiler                        0.61.0
mercantile                             1.2.1
mgwr                                   2.1.2
missingno                              0.5.2
mistune                                0.8.4
mizani                                 0.9.2
ml-dtypes                              0.1.0
mlcrate                                0.2.0
mlens                                  0.2.3
mlxtend                                0.22.0
mmh3                                   4.0.0
mne                                    1.4.2
mnist                                  0.2.2
mock                                   5.0.2
momepy                                 0.6.0
more-itertools                         9.1.0
mpld3                                  0.5.9
mpmath                                 1.3.0
msgpack                                1.0.5
msgpack-numpy                          0.4.8
multidict                              6.0.4
multimethod                            1.9.1
multipledispatch                       0.6.0
multiprocess                           0.70.14
munkres                                1.1.4
murmurhash                             1.0.9
mypy-extensions                        1.0.0
nb-conda                               2.2.1
nb-conda-kernels                       2.3.1
nbclassic                              1.0.0
nbclient                               0.5.13
nbconvert                              6.4.5
nbdime                                 3.2.0
nbformat                               5.8.0
nest-asyncio                           1.5.6
netCDF4                                1.6.4
networkx                               3.1
nibabel                                5.1.0
nilearn                                0.10.1
ninja                                  1.11.1
nltk                                   3.2.4
nose                                   1.3.7
notebook                               6.5.4
notebook-executor                      0.2
notebook_shim                          0.2.3
numba                                  0.57.0
numexpr                                2.8.4
numpy                                  1.23.5
nvidia-ml-py                           11.495.46
nvtx                                   0.2.5
oauth2client                           4.1.3
oauthlib                               3.2.2
objsize                                0.6.1
odfpy                                  1.4.1
olefile                                0.46
onnx                                   1.14.0
opacus                                 1.2.0
opencensus                             0.11.2
opencensus-context                     0.1.3
opencv-contrib-python                  4.7.0.72
opencv-python                          4.7.0.72
opencv-python-headless                 4.7.0.72
openpyxl                               3.1.2
openslide-python                       1.2.0
opentelemetry-api                      1.17.0
opentelemetry-exporter-otlp            1.17.0
opentelemetry-exporter-otlp-proto-grpc 1.17.0
opentelemetry-exporter-otlp-proto-http 1.17.0
opentelemetry-proto                    1.17.0
opentelemetry-sdk                      1.17.0
opentelemetry-semantic-conventions     0.38b0
opt-einsum                             3.3.0
optax                                  0.1.5
optuna                                 3.2.0
orbax-checkpoint                       0.2.2
orderedmultidict                       1.0.1
orjson                                 3.8.12
ortools                                9.4.1874
osmnx                                  1.1.1
overrides                              6.5.0
packaging                              21.3
pandas                                 1.5.3
pandas-datareader                      0.10.0
pandas-profiling                       3.6.6
pandas-summary                         0.2.0
pandasql                               0.7.3
pandocfilters                          1.5.0
panel                                  1.1.0
papermill                              2.4.0
param                                  1.13.0
parso                                  0.8.3
parsy                                  2.1
partd                                  1.4.0
path                                   16.6.0
path.py                                12.5.0
pathos                                 0.3.0
pathtools                              0.1.2
pathy                                  0.10.1
patsy                                  0.5.3
pdf2image                              1.16.3
pexpect                                4.8.0
phik                                   0.12.3
pickleshare                            0.7.5
Pillow                                 9.5.0
pip                                    23.1.2
pkgutil_resolve_name                   1.3.10
platformdirs                           3.5.0
plotly                                 5.14.1
plotly-express                         0.4.1
plotnine                               0.10.1
pluggy                                 1.0.0
pointpats                              2.3.0
polars                                 0.18.2
polyglot                               16.7.4
pooch                                  1.6.0
pox                                    0.3.2
ppca                                   0.0.4
ppft                                   1.7.6.6
preprocessing                          0.1.13
preshed                                3.0.8
prettytable                            3.7.0
progressbar2                           4.2.0
prometheus-client                      0.16.0
promise                                2.3
prompt-toolkit                         3.0.38
pronouncing                            0.2.0
prophet                                1.1.1
proto-plus                             1.22.2
protobuf                               3.20.3
prv-accountant                         0.1.1.post1
psutil                                 5.9.3
ptxcompiler                            0.8.1
ptyprocess                             0.7.0
pudb                                   2022.1.3
PuLP                                   2.7.0
pure-eval                              0.2.2
py-cpuinfo                             9.0.0
py-lz4framed                           0.14.0
py-spy                                 0.3.14
py4j                                   0.10.9.7
pyaml                                  23.5.9
PyArabic                               0.6.15
pyarrow                                11.0.0
pyasn1                                 0.4.8
pyasn1-modules                         0.2.7
PyAstronomy                            0.19.0
pybind11                               2.10.4
pyclipper                              1.3.0.post4
pycodestyle                            2.10.0
pycolmap                               0.4.0
pycosat                                0.6.4
pycparser                              2.21
pycryptodome                           3.18.0
pyct                                   0.5.0
pycuda                                 2022.2.2
pydantic                               1.10.7
pydegensac                             0.1.2
pydicom                                2.3.1
pydocstyle                             6.3.0
pydot                                  1.4.2
pydub                                  0.25.1
pyemd                                  1.0.0
pyerfa                                 2.0.0.3
pyexcel-io                             0.6.6
pyexcel-ods                            0.6.0
pyfasttext                             0.4.6
pyflakes                               3.0.1
pygltflib                              1.15.6
Pygments                               2.15.1
PyJWT                                  2.6.0
pykalman                               0.9.5
pyLDAvis                               3.2.2
pylibraft                              23.6.1
pylint                                 2.17.4
pymc3                                  3.11.5
PyMeeus                                0.5.12
pymongo                                3.13.0
Pympler                                1.0.1
pynndescent                            0.5.10
pynvml                                 11.4.1
pynvrtc                                9.2
pyocr                                  0.8.3
pyOpenSSL                              23.1.1
pyparsing                              3.0.9
pypdf                                  3.9.1
pyproj                                 3.6.0
pyrsistent                             0.19.3
pysal                                  23.1
pyshp                                  2.3.1
PySocks                                1.7.1
pytesseract                            0.3.10
pytest                                 7.3.2
python-bidi                            0.4.2
python-dateutil                        2.8.2
python-dotenv                          1.0.0
python-igraph                          0.10.4
python-json-logger                     2.0.7
python-Levenshtein                     0.21.1
python-louvain                         0.16
python-lsp-jsonrpc                     1.0.0
python-lsp-server                      1.7.3
python-slugify                         8.0.1
python-utils                           3.6.0
pythreejs                              2.4.2
pytoolconfig                           1.2.5
pytools                                2022.1.14
pytorch-ignite                         0.4.12
pytorch-lightning                      2.0.3
pytz                                   2023.3
pyu2f                                  0.1.5
PyUpSet                                0.1.1.post7
pyviz-comms                            2.3.1
PyWavelets                             1.4.1
PyYAML                                 5.4.1
pyzmq                                  25.0.2
qgrid                                  1.3.1
qtconsole                              5.4.3
QtPy                                   2.3.1
quantecon                              0.7.1
quantities                             0.14.1
qudida                                 0.0.4
raft-dask                              23.6.1
randomgen                              1.23.1
rapidfuzz                              3.1.1
rasterio                               1.3.7
rasterstats                            0.19.0
ray                                    2.4.0
ray-cpp                                2.4.0
regex                                  2023.5.5
requests                               2.28.2
requests-oauthlib                      1.3.1
requests-toolbelt                      0.10.1
responses                              0.18.0
retrying                               1.3.3
rfc3339-validator                      0.1.4
rfc3986-validator                      0.1.1
rgf-python                             3.12.0
rich                                   12.6.0
rmm                                    23.6.0
rope                                   1.8.0
rsa                                    4.9
Rtree                                  1.0.1
ruamel.yaml                            0.17.24
ruamel.yaml.clib                       0.2.7
ruamel-yaml-conda                      0.15.100
s2sphere                               0.2.5
s3fs                                   2023.6.0
s3transfer                             0.6.1
safetensors                            0.3.1
scattertext                            0.1.19
scikit-image                           0.20.0
scikit-learn                           1.2.2
scikit-learn-intelex                   2023.1.1
scikit-multilearn                      0.2.0
scikit-optimize                        0.9.0
scikit-plot                            0.3.7
scikit-surprise                        1.1.3
scipy                                  1.10.1
seaborn                                0.12.2
SecretStorage                          3.3.3
segment-anything                       1.0
segregation                            2.4.2
semver                                 3.0.0
Send2Trash                             1.8.2
sentencepiece                          0.1.99
sentry-sdk                             1.25.1
setproctitle                           1.3.2
setuptools                             59.8.0
setuptools-git                         1.2
setuptools-scm                         7.1.0
shap                                   0.41.0
Shapely                                1.8.5.post1
shellingham                            1.5.1
simpervisor                            0.4
SimpleITK                              2.2.1
simplejson                             3.19.1
six                                    1.16.0
sklearn-pandas                         2.2.0
slicer                                 0.0.7
smart-open                             6.3.0
smhasher                               0.150.1
smmap                                  5.0.0
sniffio                                1.3.0
snowballstemmer                        2.2.0
snuggs                                 1.4.7
sortedcontainers                       2.4.0
soundfile                              0.12.1
soupsieve                              2.3.2.post1
soxr                                   0.3.5
spacy                                  3.5.3
spacy-legacy                           3.0.12
spacy-loggers                          1.0.4
spaghetti                              1.7.3
spectral                               0.23.1
spglm                                  1.0.8
sphinx-rtd-theme                       0.2.4
spint                                  1.0.7
splot                                  1.1.5.post1
spopt                                  0.5.0
spreg                                  1.3.2
spvcm                                  0.3.0
SQLAlchemy                             2.0.12
sqlglot                                11.7.1
sqlparse                               0.4.4
squarify                               0.4.3
srsly                                  2.4.6
stack-data                             0.6.2
starlette                              0.26.1
statsmodels                            0.13.5
stemming                               1.0.1
stop-words                             2018.7.23
stopit                                 1.1.2
strip-hints                            0.1.10
stumpy                                 1.11.1
sympy                                  1.12
tables                                 3.8.0
tabulate                               0.9.0
tangled-up-in-unicode                  0.2.0
tbb                                    2021.9.0
tblib                                  1.7.0
tenacity                               8.2.2
tensorboard                            2.12.3
tensorboard-data-server                0.7.0
tensorboard-plugin-profile             2.11.2
tensorboardX                           2.6
tensorflow                             2.12.0
tensorflow-addons                      0.20.0
tensorflow-cloud                       0.1.16
tensorflow-datasets                    4.9.2
tensorflow-decision-forests            1.3.0
tensorflow-estimator                   2.12.0
tensorflow-gcs-config                  2.12.0
tensorflow-hub                         0.12.0
tensorflow-io                          0.31.0
tensorflow-io-gcs-filesystem           0.31.0
tensorflow-metadata                    0.14.0
tensorflow-probability                 0.20.0
tensorflow-serving-api                 2.12.1
tensorflow-text                        2.12.1
tensorflow-transform                   0.14.0
tensorflowjs                           3.15.0
tensorpack                             0.11
tensorstore                            0.1.37
termcolor                              2.3.0
terminado                              0.17.1
testpath                               0.6.0
text-unidecode                         1.3
textblob                               0.17.1
texttable                              1.6.7
textwrap3                              0.9.2
Theano                                 1.0.5
Theano-PyMC                            1.1.2
thinc                                  8.1.10
threadpoolctl                          3.1.0
tifffile                               2023.4.12
timm                                   0.9.2
tinycss2                               1.2.1
tobler                                 0.10
tokenizers                             0.13.3
toml                                   0.10.2
tomli                                  2.0.1
tomlkit                                0.11.8
toolz                                  0.12.0
torch                                  1.12.1
torchaudio                             2.0.1
torchdata                              0.6.0
torchinfo                              1.8.0
torchmetrics                           0.11.4
torchtext                              0.15.1
torchvision                            0.15.1
tornado                                6.3.1
TPOT                                   0.12.0
tqdm                                   4.64.1
traceml                                1.0.8
traitlets                              5.9.0
traittypes                             0.2.1
transformers                           4.30.1
treelite                               3.2.0
treelite-runtime                       3.2.0
trueskill                              0.4.5
tsfresh                                0.20.0
typeguard                              2.13.3
typer                                  0.7.0
typing_extensions                      4.5.0
typing-inspect                         0.9.0
tzlocal                                5.0.1
uc-micro-py                            1.0.2
ucx-py                                 0.32.0
ujson                                  5.8.0
umap-learn                             0.5.3
unicodedata2                           15.0.0
Unidecode                              1.3.6
update-checker                         0.18.0
uri-template                           1.2.0
uritemplate                            3.0.1
urllib3                                1.26.15
urwid                                  2.1.2
urwid-readline                         0.13
uvicorn                                0.22.0
uvloop                                 0.17.0
vaex                                   4.16.0
vaex-astro                             0.9.3
vaex-core                              4.16.1
vaex-hdf5                              0.14.1
vaex-jupyter                           0.8.1
vaex-ml                                0.18.1
vaex-server                            0.8.1
vaex-viz                               0.5.4
vecstack                               0.4.0
virtualenv                             20.21.0
visions                                0.7.5
vowpalwabbit                           9.8.0
vtk                                    9.2.6
Wand                                   0.6.11
wandb                                  0.15.4
wasabi                                 1.1.2
watchfiles                             0.19.0
wavio                                  0.0.7
wcwidth                                0.2.6
webcolors                              1.13
webencodings                           0.5.1
websocket-client                       1.5.1
websockets                             11.0.3
Werkzeug                               2.3.6
wfdb                                   4.1.1
whatthepatch                           1.0.5
wheel                                  0.40.0
widgetsnbextension                     3.6.4
witwidget                              1.8.1
woodwork                               0.24.0
Wordbatch                              1.4.9
wordcloud                              1.9.2
wordsegment                            1.3.1
wrapt                                  1.14.1
wurlitzer                              3.0.3
xarray                                 2023.5.0
xarray-einstats                        0.5.1
xgboost                                1.7.5
xvfbwrapper                            0.2.9
xxhash                                 3.2.0
xyzservices                            2023.5.0
y-py                                   0.5.9
yapf                                   0.33.0
yarl                                   1.9.1
ydata-profiling                        4.1.2
yellowbrick                            1.5
ypy-websocket                          0.8.2
zict                                   3.0.0
zipp                                   3.15.0
zstandard                              0.19.0

Could anyone help me with this?

Incompatible libraries

When I finetune GPT-2 with DP using fine-tune-dp.py in dp-transformers/research/synthetic-text-generation-with-DP. An error occurred: TypeError: read_csv() got an unexpected keyword argument 'mangle_dupe_cols'

Seems like the error is caused by the versioning of datasets, if I upgrade datasets to the latest version (2.14.6), the error disappeared, but another error occurred: ValueError: math domain error

I checked the source code and believe that this error should come from math.log(1 / q - 1) in the prv_accountant package, which is a part of dp_transformers. I was trying to upgrade df_transformers, but df_transformers requires datasets<=2.6.1,>=2.0.0, which will cause the TypeError mentioned before.

Any suggestion to avoid the incompatible libraries problem will be appreciated.
Thank you!

using dp_transformers and get error:ValueError: Requested number of compositions exceeds the maximum number of compositions

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[19], line 1
----> 1 trainer.train()

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/transformers/trainer.py:1539, in Trainer.train(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)
   1534     self.model_wrapped = self.model
   1536 inner_training_loop = find_executable_batch_size(
   1537     self._inner_training_loop, self._train_batch_size, args.auto_find_batch_size
   1538 )
-> 1539 return inner_training_loop(
   1540     args=args,
   1541     resume_from_checkpoint=resume_from_checkpoint,
   1542     trial=trial,
   1543     ignore_keys_for_eval=ignore_keys_for_eval,
   1544 )

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/transformers/trainer.py:1901, in Trainer._inner_training_loop(self, batch_size, args, resume_from_checkpoint, trial, ignore_keys_for_eval)
   1898     self.state.epoch = epoch + (step + 1 + steps_skipped) / steps_in_epoch
   1899     self.control = self.callback_handler.on_step_end(args, self.state, self.control)
-> 1901     self._maybe_log_save_evaluate(tr_loss, model, trial, epoch, ignore_keys_for_eval)
   1902 else:
   1903     self.control = self.callback_handler.on_substep_end(args, self.state, self.control)

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/transformers/trainer.py:2238, in Trainer._maybe_log_save_evaluate(self, tr_loss, model, trial, epoch, ignore_keys_for_eval)
   2236 if self.control.should_save:
   2237     self._save_checkpoint(model, trial, metrics=metrics)
-> 2238     self.control = self.callback_handler.on_save(self.args, self.state, self.control)

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/transformers/trainer_callback.py:386, in CallbackHandler.on_save(self, args, state, control)
    384 def on_save(self, args: TrainingArguments, state: TrainerState, control: TrainerControl):
    385     control.should_save = False
--> 386     return self.call_event("on_save", args, state, control)

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/transformers/trainer_callback.py:397, in CallbackHandler.call_event(self, event, args, state, control, **kwargs)
    395 def call_event(self, event, args, state, control, **kwargs):
    396     for callback in self.callbacks:
--> 397         result = getattr(callback, event)(
    398             args,
    399             state,
    400             control,
    401             model=self.model,
    402             tokenizer=self.tokenizer,
    403             optimizer=self.optimizer,
    404             lr_scheduler=self.lr_scheduler,
    405             train_dataloader=self.train_dataloader,
    406             eval_dataloader=self.eval_dataloader,
    407             **kwargs,
    408         )
    409         # A Callback can skip the return of `control` if it doesn't change it.
    410         if result is not None:

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/dp_transformers/dp_utils.py:78, in DPCallback.on_save(self, args, state, control, **kwargs)
     77 def on_save(self, args: training_args.TrainingArguments, state: TrainerState, control: TrainerControl, **kwargs):
---> 78     return self._check_max_epsilon_exceeded(state, control)

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/dp_transformers/dp_utils.py:85, in DPCallback._check_max_epsilon_exceeded(self, state, control)
     83 def _check_max_epsilon_exceeded(self, state: TrainerState, control: TrainerControl) -> TrainerControl:
     84     eps_rdp = self.compute_rdp_epsilon()
---> 85     eps_prv = self.compute_prv_epsilon(state.global_step)
     86     if eps_rdp > self.max_epsilon or eps_prv > self.max_epsilon:
     87         logger.error("Max epsilon exceeded. Stopping training...")

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/dp_transformers/dp_utils.py:49, in DPCallback.__init__.<locals>.<lambda>(s)
     47 self.on_substep_end_was_called = False
     48 self.compute_rdp_epsilon = lambda: self.rdp_accountant.get_epsilon(self.target_delta)
---> 49 self.compute_prv_epsilon = lambda s: self.prv_accountant.compute_epsilon(s)[2]

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/prv_accountant/accountant.py:99, in Accountant.compute_epsilon(self, num_compositions)
     90 def compute_epsilon(self, num_compositions: int) -> Tuple[float, float, float]:
     91     """
     92     Compute epsilon bounds
     93 
   (...)
     97                                        upper bound of true epsilon
     98     """
---> 99     f_n = self.compute_compositions(num_compositions=num_compositions)
    100     return f_n.compute_epsilon(self.delta, self.delta_error, self.eps_error)

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/prv_accountant/accountant.py:77, in Accountant.compute_compositions(self, num_compositions)
     75 def compute_compositions(self, num_compositions: int) -> DiscretePrivacyRandomVariable:
     76     if num_compositions > self.max_compositions:
---> 77         raise ValueError("Requested number of compositions exceeds the maximum number of compositions")
     78     return self.composer.compute_composition(num_compositions)

ValueError: Requested number of compositions exceeds the maximum number of compositions

code can be found: https://github.com/Ethan-Chen-plus/dp_with_llm/blob/master/main-csv-dp.ipynb
image

How to load GPT2 model after DP?

after dp-finetune gpt2:
image
image
image
I got:

Some weights of the model checkpoint at ./scratch/checkpoint-3500 were not used when initializing GPT2LMHeadModel

image
After fine-tuning, the results generated by GPT-2 have a lot of garbled characters.

`use_amp` has been deprecated on `transformers.Trainer`

On this PR https://github.com/huggingface/transformers/pull/17138/files use_amp has been deprecated in favor of use_cpu_amp and use_cuda_amp. This is causing our experiments to fail due to


and

We can either freeze the transformers version we use or update this. There is a broader discussion about this on @donebydan's PR #5.

Cannot import name 'convert_gpt2_attention_to_lora' from 'dp_transformers.module_modification'

I finetuned GPT-2 with LORA using the latest dp-transformers library and 1 GPU. I am now trying to use the fine-tuned model to generate synthetic private text data using the following command-line code script following the instruction on this page:

python3 generate-text.py \
    --model_type gpt2 \
    --model_name_or_path output \
    --input_training_file data \
    --output_dir synthetic_data \
    --length 128 \
    --total_sequences 100 \
    --do_sample \
    --batch_size 8 \
    --lora_dim 4 \
    --lora_alpha 32 \
    --lora_dropout`` 0.0 \

However, an error occurred: ImportError: cannot import name 'convert_gpt2_attention_to_lora' from 'dp_transformers.module_modification' I checked the source code of dp_transformers.module_modification and found that there is indeed no function called convert_gpt2_attention_to_lora. Will the library be updated to make sure the synthetic private text generation could work?

Thanks for your time.

issue while training with dp_lora

[INFO|trainer.py:762] 2023-08-17 22:43:40,796 >> The following columns in the training set don't have a corresponding argument in `GradSampleModule.forward` and have been ignored: attention_mask, input_ids. If attention_mask, input_ids are not expected by `GradSampleModule.forward`,  you can safely ignore this message.
/root/anaconda3/envs/LLM/lib/python3.11/site-packages/transformers/optimization.py:391: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use the PyTorch implementation torch.optim.AdamW instead, or set `no_deprecation_warning=True` to disable this warning
  warnings.warn(
[INFO|trainer.py:1769] 2023-08-17 22:43:40,817 >> ***** Running training *****
[INFO|trainer.py:1770] 2023-08-17 22:43:40,818 >>   Num examples = 0
[INFO|trainer.py:1771] 2023-08-17 22:43:40,818 >>   Num Epochs = 3
[INFO|trainer.py:1772] 2023-08-17 22:43:40,819 >>   Instantaneous batch size per device = 32
[INFO|trainer.py:1773] 2023-08-17 22:43:40,819 >>   Total train batch size (w. parallel, distributed & accumulation) = 64
[INFO|trainer.py:1774] 2023-08-17 22:43:40,819 >>   Gradient Accumulation steps = 2
[INFO|trainer.py:1775] 2023-08-17 22:43:40,820 >>   Total optimization steps = 22,968
[INFO|trainer.py:1776] 2023-08-17 22:43:40,821 >>   Number of trainable parameters = 147,456
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[65], line 2
      1 try:
----> 2     trainer.train()
      3 finally:
      4     eps_prv = trainer.get_prv_epsilon()

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/transformers/trainer.py:1662, in Trainer.train(self, resume_from_checkpoint, trial, ignore_keys_for_eval, **kwargs)
   1657     self.model_wrapped = self.model
   1659 inner_training_loop = find_executable_batch_size(
   1660     self._inner_training_loop, self._train_batch_size, args.auto_find_batch_size
   1661 )
-> 1662 return inner_training_loop(
   1663     args=args,
   1664     resume_from_checkpoint=resume_from_checkpoint,
   1665     trial=trial,
   1666     ignore_keys_for_eval=ignore_keys_for_eval,
   1667 )

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/transformers/trainer.py:1899, in Trainer._inner_training_loop(self, batch_size, args, resume_from_checkpoint, trial, ignore_keys_for_eval)
   1896     rng_to_sync = True
   1898 step = -1
-> 1899 for step, inputs in enumerate(epoch_iterator):
   1900     total_batched_samples += 1
   1901     if rng_to_sync:

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/torch/utils/data/dataloader.py:633, in _BaseDataLoaderIter.__next__(self)
    630 if self._sampler_iter is None:
    631     # TODO(https://github.com/pytorch/pytorch/issues/76750)
    632     self._reset()  # type: ignore[call-arg]
--> 633 data = self._next_data()
    634 self._num_yielded += 1
    635 if self._dataset_kind == _DatasetKind.Iterable and \
    636         self._IterableDataset_len_called is not None and \
    637         self._num_yielded > self._IterableDataset_len_called:

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/torch/utils/data/dataloader.py:1345, in _MultiProcessingDataLoaderIter._next_data(self)
   1343 else:
   1344     del self._task_info[idx]
-> 1345     return self._process_data(data)

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/torch/utils/data/dataloader.py:1371, in _MultiProcessingDataLoaderIter._process_data(self, data)
   1369 self._try_put_index()
   1370 if isinstance(data, ExceptionWrapper):
-> 1371     data.reraise()
   1372 return data

File ~/anaconda3/envs/LLM/lib/python3.11/site-packages/torch/_utils.py:644, in ExceptionWrapper.reraise(self)
    640 except TypeError:
    641     # If the exception takes multiple arguments, don't try to
    642     # instantiate since we don't know how to
    643     raise RuntimeError(msg) from None
--> 644 raise exception

IndexError: Caught IndexError in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/root/anaconda3/envs/LLM/lib/python3.11/site-packages/torch/utils/data/_utils/worker.py", line 308, in _worker_loop
    data = fetcher.fetch(index)
           ^^^^^^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/LLM/lib/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch
    data = self.dataset.__getitems__(possibly_batched_index)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/LLM/lib/python3.11/site-packages/datasets/arrow_dataset.py", line 2807, in __getitems__
    batch = self.__getitem__(keys)
            ^^^^^^^^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/LLM/lib/python3.11/site-packages/datasets/arrow_dataset.py", line 2803, in __getitem__
    return self._getitem(key)
           ^^^^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/LLM/lib/python3.11/site-packages/datasets/arrow_dataset.py", line 2787, in _getitem
    pa_subtable = query_table(self._data, key, indices=self._indices if self._indices is not None else None)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/anaconda3/envs/LLM/lib/python3.11/site-packages/datasets/formatting/formatting.py", line 583, in query_table
    _check_valid_index_key(key, size)
  File "/root/anaconda3/envs/LLM/lib/python3.11/site-packages/datasets/formatting/formatting.py", line 536, in _check_valid_index_key
    _check_valid_index_key(int(max(key)), size=size)
  File "/root/anaconda3/envs/LLM/lib/python3.11/site-packages/datasets/formatting/formatting.py", line 526, in _check_valid_index_key
    raise IndexError(f"Invalid key: {key} is out of bounds for size {size}")
IndexError: Invalid key: 419297 is out of bounds for size 0

my notebook can be accessed:
https://github.com/Ethan-Chen-plus/fine_tune_dp/blob/main/fine_tune_dp.ipynb

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.