From 19e559d5e91920e8637ba6391a6c42537b404d88 Mon Sep 17 00:00:00 2001 From: Suraj Patil Date: Wed, 5 Oct 2022 17:40:49 +0200 Subject: [PATCH] remove use_auth_token from remaining places (#737) remove use_auth_token --- docs/source/training/text_inversion.mdx | 4 +-- examples/dreambooth/README.md | 8 ++--- examples/dreambooth/train_dreambooth.py | 30 ++++--------------- examples/textual_inversion/README.md | 4 +-- .../textual_inversion/textual_inversion.py | 24 +++------------ .../pipelines/stable_diffusion/README.md | 8 ++--- 6 files changed, 20 insertions(+), 58 deletions(-) diff --git a/docs/source/training/text_inversion.mdx b/docs/source/training/text_inversion.mdx index 8c53421e21..82cb12902f 100644 --- a/docs/source/training/text_inversion.mdx +++ b/docs/source/training/text_inversion.mdx @@ -74,7 +74,7 @@ Run the following command to authenticate your token huggingface-cli login ``` -If you have already cloned the repo, then you won't need to go through these steps. You can simple remove the `--use_auth_token` arg from the following command. +If you have already cloned the repo, then you won't need to go through these steps.
@@ -87,7 +87,7 @@ export MODEL_NAME="CompVis/stable-diffusion-v1-4" export DATA_DIR="path-to-dir-containing-images" accelerate launch textual_inversion.py \ - --pretrained_model_name_or_path=$MODEL_NAME --use_auth_token \ + --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATA_DIR \ --learnable_property="object" \ --placeholder_token="" --initializer_token="toy" \ diff --git a/examples/dreambooth/README.md b/examples/dreambooth/README.md index e6dbf9667e..9d78c11282 100644 --- a/examples/dreambooth/README.md +++ b/examples/dreambooth/README.md @@ -32,7 +32,7 @@ Run the following command to authenticate your token huggingface-cli login ``` -If you have already cloned the repo, then you won't need to go through these steps. You can simple remove the `--use_auth_token` arg from the following command. +If you have already cloned the repo, then you won't need to go through these steps.
@@ -46,7 +46,7 @@ export INSTANCE_DIR="path-to-instance-images" export OUTPUT_DIR="path-to-save-model" accelerate launch train_dreambooth.py \ - --pretrained_model_name_or_path=$MODEL_NAME --use_auth_token \ + --pretrained_model_name_or_path=$MODEL_NAME \ --instance_data_dir=$INSTANCE_DIR \ --output_dir=$OUTPUT_DIR \ --instance_prompt="a photo of sks dog" \ @@ -71,7 +71,7 @@ export CLASS_DIR="path-to-class-images" export OUTPUT_DIR="path-to-save-model" accelerate launch train_dreambooth.py \ - --pretrained_model_name_or_path=$MODEL_NAME --use_auth_token \ + --pretrained_model_name_or_path=$MODEL_NAME \ --instance_data_dir=$INSTANCE_DIR \ --class_data_dir=$CLASS_DIR \ --output_dir=$OUTPUT_DIR \ @@ -101,7 +101,7 @@ export CLASS_DIR="path-to-class-images" export OUTPUT_DIR="path-to-save-model" accelerate launch train_dreambooth.py \ - --pretrained_model_name_or_path=$MODEL_NAME --use_auth_token \ + --pretrained_model_name_or_path=$MODEL_NAME \ --instance_data_dir=$INSTANCE_DIR \ --class_data_dir=$CLASS_DIR \ --output_dir=$OUTPUT_DIR \ diff --git a/examples/dreambooth/train_dreambooth.py b/examples/dreambooth/train_dreambooth.py index 740724c490..e507fcbdca 100644 --- a/examples/dreambooth/train_dreambooth.py +++ b/examples/dreambooth/train_dreambooth.py @@ -158,14 +158,6 @@ def parse_args(): parser.add_argument("--adam_epsilon", type=float, default=1e-08, help="Epsilon value for the Adam optimizer") parser.add_argument("--max_grad_norm", default=1.0, type=float, help="Max gradient norm.") parser.add_argument("--push_to_hub", action="store_true", help="Whether or not to push the model to the Hub.") - parser.add_argument( - "--use_auth_token", - action="store_true", - help=( - "Will use the token generated when running `huggingface-cli login` (necessary to use this script with" - " private models)." - ), - ) parser.add_argument("--hub_token", type=str, default=None, help="The token to use to push to the Model Hub.") parser.add_argument( "--hub_model_id", @@ -341,7 +333,7 @@ def main(): if cur_class_images < args.num_class_images: torch_dtype = torch.float16 if accelerator.device.type == "cuda" else torch.float32 pipeline = StableDiffusionPipeline.from_pretrained( - args.pretrained_model_name_or_path, use_auth_token=args.use_auth_token, torch_dtype=torch_dtype + args.pretrained_model_name_or_path, torch_dtype=torch_dtype ) pipeline.set_progress_bar_config(disable=True) @@ -389,20 +381,12 @@ def main(): if args.tokenizer_name: tokenizer = CLIPTokenizer.from_pretrained(args.tokenizer_name) elif args.pretrained_model_name_or_path: - tokenizer = CLIPTokenizer.from_pretrained( - args.pretrained_model_name_or_path, subfolder="tokenizer", use_auth_token=args.use_auth_token - ) + tokenizer = CLIPTokenizer.from_pretrained(args.pretrained_model_name_or_path, subfolder="tokenizer") # Load models and create wrapper for stable diffusion - text_encoder = CLIPTextModel.from_pretrained( - args.pretrained_model_name_or_path, subfolder="text_encoder", use_auth_token=args.use_auth_token - ) - vae = AutoencoderKL.from_pretrained( - args.pretrained_model_name_or_path, subfolder="vae", use_auth_token=args.use_auth_token - ) - unet = UNet2DConditionModel.from_pretrained( - args.pretrained_model_name_or_path, subfolder="unet", use_auth_token=args.use_auth_token - ) + text_encoder = CLIPTextModel.from_pretrained(args.pretrained_model_name_or_path, subfolder="text_encoder") + vae = AutoencoderKL.from_pretrained(args.pretrained_model_name_or_path, subfolder="vae") + unet = UNet2DConditionModel.from_pretrained(args.pretrained_model_name_or_path, subfolder="unet") if args.gradient_checkpointing: unet.enable_gradient_checkpointing() @@ -589,9 +573,7 @@ def main(): # Create the pipeline using using the trained modules and save it. if accelerator.is_main_process: pipeline = StableDiffusionPipeline.from_pretrained( - args.pretrained_model_name_or_path, - unet=accelerator.unwrap_model(unet), - use_auth_token=args.use_auth_token, + args.pretrained_model_name_or_path, unet=accelerator.unwrap_model(unet) ) pipeline.save_pretrained(args.output_dir) diff --git a/examples/textual_inversion/README.md b/examples/textual_inversion/README.md index 4e3873024e..0976e73496 100644 --- a/examples/textual_inversion/README.md +++ b/examples/textual_inversion/README.md @@ -39,7 +39,7 @@ Run the following command to authenticate your token huggingface-cli login ``` -If you have already cloned the repo, then you won't need to go through these steps. You can simple remove the `--use_auth_token` arg from the following command. +If you have already cloned the repo, then you won't need to go through these steps.
@@ -52,7 +52,7 @@ export MODEL_NAME="CompVis/stable-diffusion-v1-4" export DATA_DIR="path-to-dir-containing-images" accelerate launch textual_inversion.py \ - --pretrained_model_name_or_path=$MODEL_NAME --use_auth_token \ + --pretrained_model_name_or_path=$MODEL_NAME \ --train_data_dir=$DATA_DIR \ --learnable_property="object" \ --placeholder_token="" --initializer_token="toy" \ diff --git a/examples/textual_inversion/textual_inversion.py b/examples/textual_inversion/textual_inversion.py index 253063e793..5b5ba9a207 100644 --- a/examples/textual_inversion/textual_inversion.py +++ b/examples/textual_inversion/textual_inversion.py @@ -136,14 +136,6 @@ def parse_args(): parser.add_argument("--adam_weight_decay", type=float, default=1e-2, help="Weight decay to use.") parser.add_argument("--adam_epsilon", type=float, default=1e-08, help="Epsilon value for the Adam optimizer") parser.add_argument("--push_to_hub", action="store_true", help="Whether or not to push the model to the Hub.") - parser.add_argument( - "--use_auth_token", - action="store_true", - help=( - "Will use the token generated when running `huggingface-cli login` (necessary to use this script with" - " private models)." - ), - ) parser.add_argument("--hub_token", type=str, default=None, help="The token to use to push to the Model Hub.") parser.add_argument( "--hub_model_id", @@ -371,9 +363,7 @@ def main(): if args.tokenizer_name: tokenizer = CLIPTokenizer.from_pretrained(args.tokenizer_name) elif args.pretrained_model_name_or_path: - tokenizer = CLIPTokenizer.from_pretrained( - args.pretrained_model_name_or_path, subfolder="tokenizer", use_auth_token=args.use_auth_token - ) + tokenizer = CLIPTokenizer.from_pretrained(args.pretrained_model_name_or_path, subfolder="tokenizer") # Add the placeholder token in tokenizer num_added_tokens = tokenizer.add_tokens(args.placeholder_token) @@ -393,15 +383,9 @@ def main(): placeholder_token_id = tokenizer.convert_tokens_to_ids(args.placeholder_token) # Load models and create wrapper for stable diffusion - text_encoder = CLIPTextModel.from_pretrained( - args.pretrained_model_name_or_path, subfolder="text_encoder", use_auth_token=args.use_auth_token - ) - vae = AutoencoderKL.from_pretrained( - args.pretrained_model_name_or_path, subfolder="vae", use_auth_token=args.use_auth_token - ) - unet = UNet2DConditionModel.from_pretrained( - args.pretrained_model_name_or_path, subfolder="unet", use_auth_token=args.use_auth_token - ) + text_encoder = CLIPTextModel.from_pretrained(args.pretrained_model_name_or_path, subfolder="text_encoder") + vae = AutoencoderKL.from_pretrained(args.pretrained_model_name_or_path, subfolder="vae") + unet = UNet2DConditionModel.from_pretrained(args.pretrained_model_name_or_path, subfolder="unet") # Resize the token embeddings as we are adding new special tokens to the tokenizer text_encoder.resize_token_embeddings(len(tokenizer)) diff --git a/src/diffusers/pipelines/stable_diffusion/README.md b/src/diffusers/pipelines/stable_diffusion/README.md index 91930d89d4..47c38acbdb 100644 --- a/src/diffusers/pipelines/stable_diffusion/README.md +++ b/src/diffusers/pipelines/stable_diffusion/README.md @@ -28,16 +28,12 @@ download the weights with `git lfs install; git clone https://huggingface.co/Com ### Using Stable Diffusion without being logged into the Hub. -If you want to download the model weights using a single Python line, you need to pass the token -to `use_auth_token` or be logged in via `huggingface-cli login`. -For more information on access tokens, please refer to [this section](https://huggingface.co/docs/hub/security-tokens) of the documentation. - -Assuming your token is stored under YOUR_TOKEN, you can download the stable diffusion pipeline as follows: +If you want to download the model weights using a single Python line, you need to be logged in via `huggingface-cli login`. ```python from diffusers import DiffusionPipeline -pipeline = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN) +pipeline = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4") ``` This however can make it difficult to build applications on top of `diffusers` as you will always have to pass the token around. A potential way to solve this issue is by downloading the weights to a local path `"./stable-diffusion-v1-4"`: