Unverified Commit c2283310 authored by Suraj Patil's avatar Suraj Patil Committed by GitHub
Browse files

[examples] add check_min_version (#1550)



* add check_min_version for examples

* move __version__ to the top

* Apply suggestions from code review
Co-authored-by: default avatarPedro Cuenca <pedro@huggingface.co>

* fix comment

* fix error_message

* adapt the install message
Co-authored-by: default avatarPedro Cuenca <pedro@huggingface.co>
parent ae4112d2
...@@ -9,8 +9,18 @@ The `train_dreambooth.py` script shows how to implement the training procedure a ...@@ -9,8 +9,18 @@ The `train_dreambooth.py` script shows how to implement the training procedure a
Before running the scripts, make sure to install the library's training dependencies: Before running the scripts, make sure to install the library's training dependencies:
**Important**
To make sure you can successfully run the latest versions of the example scripts, we highly recommend **installing from source** and keeping the install up to date as we update the example scripts frequently and install some example-specific requirements. To do this, execute the following steps in a new virtual environment:
```bash
git clone https://github.com/huggingface/diffusers
cd diffusers
pip install -e .
```
Then cd in the example folder and run
```bash ```bash
pip install -U -r requirements.txt pip install -r requirements.txt
``` ```
And initialize an [🤗Accelerate](https://github.com/huggingface/accelerate/) environment with: And initialize an [🤗Accelerate](https://github.com/huggingface/accelerate/) environment with:
......
diffusers>==0.5.0
accelerate accelerate
torchvision torchvision
transformers>=4.21.0 transformers>=4.21.0
......
diffusers>==0.5.1
transformers>=4.21.0 transformers>=4.21.0
flax flax
optax optax
......
...@@ -16,6 +16,7 @@ from accelerate.logging import get_logger ...@@ -16,6 +16,7 @@ from accelerate.logging import get_logger
from accelerate.utils import set_seed from accelerate.utils import set_seed
from diffusers import AutoencoderKL, DDPMScheduler, DiffusionPipeline, UNet2DConditionModel from diffusers import AutoencoderKL, DDPMScheduler, DiffusionPipeline, UNet2DConditionModel
from diffusers.optimization import get_scheduler from diffusers.optimization import get_scheduler
from diffusers.utils import check_min_version
from huggingface_hub import HfFolder, Repository, whoami from huggingface_hub import HfFolder, Repository, whoami
from PIL import Image from PIL import Image
from torchvision import transforms from torchvision import transforms
...@@ -23,6 +24,9 @@ from tqdm.auto import tqdm ...@@ -23,6 +24,9 @@ from tqdm.auto import tqdm
from transformers import AutoTokenizer, PretrainedConfig from transformers import AutoTokenizer, PretrainedConfig
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.10.0.dev0")
logger = get_logger(__name__) logger = get_logger(__name__)
......
...@@ -23,6 +23,7 @@ from diffusers import ( ...@@ -23,6 +23,7 @@ from diffusers import (
FlaxUNet2DConditionModel, FlaxUNet2DConditionModel,
) )
from diffusers.pipelines.stable_diffusion import FlaxStableDiffusionSafetyChecker from diffusers.pipelines.stable_diffusion import FlaxStableDiffusionSafetyChecker
from diffusers.utils import check_min_version
from flax import jax_utils from flax import jax_utils
from flax.training import train_state from flax.training import train_state
from flax.training.common_utils import shard from flax.training.common_utils import shard
...@@ -33,6 +34,9 @@ from tqdm.auto import tqdm ...@@ -33,6 +34,9 @@ from tqdm.auto import tqdm
from transformers import CLIPFeatureExtractor, CLIPTokenizer, FlaxCLIPTextModel, set_seed from transformers import CLIPFeatureExtractor, CLIPTokenizer, FlaxCLIPTextModel, set_seed
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.10.0.dev0")
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
......
...@@ -24,6 +24,7 @@ from diffusers import ( ...@@ -24,6 +24,7 @@ from diffusers import (
UNet2DConditionModel, UNet2DConditionModel,
) )
from diffusers.optimization import get_scheduler from diffusers.optimization import get_scheduler
from diffusers.utils import check_min_version
from huggingface_hub import HfFolder, Repository, whoami from huggingface_hub import HfFolder, Repository, whoami
from PIL import Image, ImageDraw from PIL import Image, ImageDraw
from torchvision import transforms from torchvision import transforms
...@@ -31,6 +32,9 @@ from tqdm.auto import tqdm ...@@ -31,6 +32,9 @@ from tqdm.auto import tqdm
from transformers import CLIPTextModel, CLIPTokenizer from transformers import CLIPTextModel, CLIPTokenizer
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.10.0.dev0")
logger = get_logger(__name__) logger = get_logger(__name__)
......
...@@ -12,9 +12,18 @@ ___This script is experimental. The script fine-tunes the whole model and often ...@@ -12,9 +12,18 @@ ___This script is experimental. The script fine-tunes the whole model and often
Before running the scripts, make sure to install the library's training dependencies: Before running the scripts, make sure to install the library's training dependencies:
**Important**
To make sure you can successfully run the latest versions of the example scripts, we highly recommend **installing from source** and keeping the install up to date as we update the example scripts frequently and install some example-specific requirements. To do this, execute the following steps in a new virtual environment:
```bash
git clone https://github.com/huggingface/diffusers
cd diffusers
pip install .
```
Then cd in the example folder and run
```bash ```bash
pip install "git+https://github.com/huggingface/diffusers.git#egg=diffusers[training]" pip install -r requirements.txt
pip install -U -r requirements.txt
``` ```
And initialize an [🤗Accelerate](https://github.com/huggingface/accelerate/) environment with: And initialize an [🤗Accelerate](https://github.com/huggingface/accelerate/) environment with:
......
diffusers==0.4.1
accelerate accelerate
torchvision torchvision
transformers>=4.21.0 transformers>=4.21.0
datasets
ftfy ftfy
tensorboard tensorboard
modelcards modelcards
\ No newline at end of file
diffusers>==0.5.1
transformers>=4.21.0 transformers>=4.21.0
datasets
flax flax
optax optax
torch torch
......
...@@ -17,12 +17,16 @@ from accelerate.utils import set_seed ...@@ -17,12 +17,16 @@ from accelerate.utils import set_seed
from datasets import load_dataset from datasets import load_dataset
from diffusers import AutoencoderKL, DDPMScheduler, StableDiffusionPipeline, UNet2DConditionModel from diffusers import AutoencoderKL, DDPMScheduler, StableDiffusionPipeline, UNet2DConditionModel
from diffusers.optimization import get_scheduler from diffusers.optimization import get_scheduler
from diffusers.utils import check_min_version
from huggingface_hub import HfFolder, Repository, whoami from huggingface_hub import HfFolder, Repository, whoami
from torchvision import transforms from torchvision import transforms
from tqdm.auto import tqdm from tqdm.auto import tqdm
from transformers import CLIPTextModel, CLIPTokenizer from transformers import CLIPTextModel, CLIPTokenizer
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.10.0.dev0")
logger = get_logger(__name__) logger = get_logger(__name__)
......
...@@ -23,6 +23,7 @@ from diffusers import ( ...@@ -23,6 +23,7 @@ from diffusers import (
FlaxUNet2DConditionModel, FlaxUNet2DConditionModel,
) )
from diffusers.pipelines.stable_diffusion import FlaxStableDiffusionSafetyChecker from diffusers.pipelines.stable_diffusion import FlaxStableDiffusionSafetyChecker
from diffusers.utils import check_min_version
from flax import jax_utils from flax import jax_utils
from flax.training import train_state from flax.training import train_state
from flax.training.common_utils import shard from flax.training.common_utils import shard
...@@ -32,6 +33,9 @@ from tqdm.auto import tqdm ...@@ -32,6 +33,9 @@ from tqdm.auto import tqdm
from transformers import CLIPFeatureExtractor, CLIPTokenizer, FlaxCLIPTextModel, set_seed from transformers import CLIPFeatureExtractor, CLIPTokenizer, FlaxCLIPTextModel, set_seed
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.10.0.dev0")
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
......
...@@ -16,8 +16,18 @@ Colab for inference ...@@ -16,8 +16,18 @@ Colab for inference
Before running the scripts, make sure to install the library's training dependencies: Before running the scripts, make sure to install the library's training dependencies:
**Important**
To make sure you can successfully run the latest versions of the example scripts, we highly recommend **installing from source** and keeping the install up to date as we update the example scripts frequently and install some example-specific requirements. To do this, execute the following steps in a new virtual environment:
```bash
git clone https://github.com/huggingface/diffusers
cd diffusers
pip install .
```
Then cd in the example folder and run
```bash ```bash
pip install diffusers"[training]" accelerate "transformers>=4.21.0" pip install -r requirements.txt
``` ```
And initialize an [🤗Accelerate](https://github.com/huggingface/accelerate/) environment with: And initialize an [🤗Accelerate](https://github.com/huggingface/accelerate/) environment with:
......
accelerate accelerate
torchvision torchvision
transformers>=4.21.0 transformers>=4.21.0
ftfy
tensorboard
modelcards
\ No newline at end of file
diffusers>==0.5.1
transformers>=4.21.0 transformers>=4.21.0
flax flax
optax optax
......
...@@ -19,6 +19,7 @@ from accelerate.utils import set_seed ...@@ -19,6 +19,7 @@ from accelerate.utils import set_seed
from diffusers import AutoencoderKL, DDPMScheduler, PNDMScheduler, StableDiffusionPipeline, UNet2DConditionModel from diffusers import AutoencoderKL, DDPMScheduler, PNDMScheduler, StableDiffusionPipeline, UNet2DConditionModel
from diffusers.optimization import get_scheduler from diffusers.optimization import get_scheduler
from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker from diffusers.pipelines.stable_diffusion import StableDiffusionSafetyChecker
from diffusers.utils import check_min_version
from huggingface_hub import HfFolder, Repository, whoami from huggingface_hub import HfFolder, Repository, whoami
# TODO: remove and import from diffusers.utils when the new version of diffusers is released # TODO: remove and import from diffusers.utils when the new version of diffusers is released
...@@ -48,6 +49,10 @@ else: ...@@ -48,6 +49,10 @@ else:
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.10.0.dev0")
logger = get_logger(__name__) logger = get_logger(__name__)
......
...@@ -24,6 +24,7 @@ from diffusers import ( ...@@ -24,6 +24,7 @@ from diffusers import (
FlaxUNet2DConditionModel, FlaxUNet2DConditionModel,
) )
from diffusers.pipelines.stable_diffusion import FlaxStableDiffusionSafetyChecker from diffusers.pipelines.stable_diffusion import FlaxStableDiffusionSafetyChecker
from diffusers.utils import check_min_version
from flax import jax_utils from flax import jax_utils
from flax.training import train_state from flax.training import train_state
from flax.training.common_utils import shard from flax.training.common_utils import shard
...@@ -55,6 +56,9 @@ else: ...@@ -55,6 +56,9 @@ else:
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.10.0.dev0")
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
......
...@@ -6,10 +6,21 @@ Creating a training image set is [described in a different document](https://hug ...@@ -6,10 +6,21 @@ Creating a training image set is [described in a different document](https://hug
Before running the scripts, make sure to install the library's training dependencies: Before running the scripts, make sure to install the library's training dependencies:
**Important**
To make sure you can successfully run the latest versions of the example scripts, we highly recommend **installing from source** and keeping the install up to date as we update the example scripts frequently and install some example-specific requirements. To do this, execute the following steps in a new virtual environment:
```bash ```bash
pip install diffusers[training] accelerate datasets tensorboard git clone https://github.com/huggingface/diffusers
cd diffusers
pip install .
``` ```
Then cd in the example folder and run
```bash
pip install -r requirements.txt
```
And initialize an [🤗Accelerate](https://github.com/huggingface/accelerate/) environment with: And initialize an [🤗Accelerate](https://github.com/huggingface/accelerate/) environment with:
```bash ```bash
......
...@@ -11,11 +11,11 @@ import torch.nn.functional as F ...@@ -11,11 +11,11 @@ import torch.nn.functional as F
from accelerate import Accelerator from accelerate import Accelerator
from accelerate.logging import get_logger from accelerate.logging import get_logger
from datasets import load_dataset from datasets import load_dataset
from diffusers import DDPMPipeline, DDPMScheduler, UNet2DModel, __version__ from diffusers import DDPMPipeline, DDPMScheduler, UNet2DModel
from diffusers.optimization import get_scheduler from diffusers.optimization import get_scheduler
from diffusers.training_utils import EMAModel from diffusers.training_utils import EMAModel
from diffusers.utils import check_min_version
from huggingface_hub import HfFolder, Repository, whoami from huggingface_hub import HfFolder, Repository, whoami
from packaging import version
from torchvision.transforms import ( from torchvision.transforms import (
CenterCrop, CenterCrop,
Compose, Compose,
...@@ -28,8 +28,11 @@ from torchvision.transforms import ( ...@@ -28,8 +28,11 @@ from torchvision.transforms import (
from tqdm.auto import tqdm from tqdm.auto import tqdm
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.10.0.dev0")
logger = get_logger(__name__) logger = get_logger(__name__)
diffusers_version = version.parse(version.parse(__version__).base_version)
def _extract_into_tensor(arr, timesteps, broadcast_shape): def _extract_into_tensor(arr, timesteps, broadcast_shape):
......
...@@ -13,6 +13,7 @@ from datasets import load_dataset ...@@ -13,6 +13,7 @@ from datasets import load_dataset
from diffusers import DDPMPipeline, DDPMScheduler, UNet2DModel from diffusers import DDPMPipeline, DDPMScheduler, UNet2DModel
from diffusers.optimization import get_scheduler from diffusers.optimization import get_scheduler
from diffusers.training_utils import EMAModel from diffusers.training_utils import EMAModel
from diffusers.utils import check_min_version
from huggingface_hub import HfFolder, Repository, whoami from huggingface_hub import HfFolder, Repository, whoami
from onnxruntime.training.ortmodule import ORTModule from onnxruntime.training.ortmodule import ORTModule
from torchvision.transforms import ( from torchvision.transforms import (
...@@ -27,6 +28,9 @@ from torchvision.transforms import ( ...@@ -27,6 +28,9 @@ from torchvision.transforms import (
from tqdm.auto import tqdm from tqdm.auto import tqdm
# Will error if the minimal version of diffusers is not installed. Remove at your own risks.
check_min_version("0.10.0.dev0")
logger = get_logger(__name__) logger = get_logger(__name__)
......
__version__ = "0.10.0.dev0"
from .configuration_utils import ConfigMixin
from .onnx_utils import OnnxRuntimeModel
from .utils import ( from .utils import (
is_flax_available, is_flax_available,
is_inflect_available, is_inflect_available,
...@@ -6,16 +10,10 @@ from .utils import ( ...@@ -6,16 +10,10 @@ from .utils import (
is_torch_available, is_torch_available,
is_transformers_available, is_transformers_available,
is_unidecode_available, is_unidecode_available,
logging,
) )
__version__ = "0.10.0.dev0"
from .configuration_utils import ConfigMixin
from .onnx_utils import OnnxRuntimeModel
from .utils import logging
if is_torch_available(): if is_torch_available():
from .modeling_utils import ModelMixin from .modeling_utils import ModelMixin
from .models import AutoencoderKL, Transformer2DModel, UNet1DModel, UNet2DConditionModel, UNet2DModel, VQModel from .models import AutoencoderKL, Transformer2DModel, UNet1DModel, UNet2DConditionModel, UNet2DModel, VQModel
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment