-
Notifications
You must be signed in to change notification settings - Fork 321
Use replicate-weights #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,20 @@ | ||
| # The .dockerignore file excludes files from the container build process. | ||
| # | ||
| # https://docs.docker.com/engine/reference/builder/#dockerignore-file | ||
|
|
||
| # Exclude Git files | ||
| .git | ||
| .github | ||
| .gitignore | ||
|
|
||
| # Exclude Python cache files | ||
| __pycache__ | ||
| .mypy_cache | ||
| .pytest_cache | ||
| .ruff_cache | ||
|
|
||
| # Exclude weights | ||
| diffusers-cache | ||
|
|
||
| # Exclude Python virtual environment | ||
| /venv |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| .cog/ | ||
| .vscode/ | ||
| __pycache__/ | ||
| diffusers-cache/ | ||
| diffusers-cache/ | ||
| .cog/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,33 +4,48 @@ | |
| import torch | ||
| from cog import BasePredictor, Input, Path | ||
| from diffusers import ( | ||
| StableDiffusionPipeline, | ||
| PNDMScheduler, | ||
| LMSDiscreteScheduler, | ||
| DDIMScheduler, | ||
| EulerDiscreteScheduler, | ||
| EulerAncestralDiscreteScheduler, | ||
| DPMSolverMultistepScheduler, | ||
| EulerAncestralDiscreteScheduler, | ||
| EulerDiscreteScheduler, | ||
| LMSDiscreteScheduler, | ||
| PNDMScheduler, | ||
| StableDiffusionPipeline, | ||
| ) | ||
| from diffusers.pipelines.stable_diffusion.safety_checker import ( | ||
| StableDiffusionSafetyChecker, | ||
| ) | ||
|
|
||
| from weights_downloader import WeightsDownloader | ||
|
|
||
| # MODEL_ID refers to a diffusers-compatible model on HuggingFace | ||
| # e.g. prompthero/openjourney-v2, wavymulder/Analog-Diffusion, etc | ||
| MODEL_ID = "stabilityai/stable-diffusion-2-1" | ||
| MODEL_CACHE = "diffusers-cache" | ||
|
|
||
| SD_MODEL_CACHE = os.path.join(MODEL_CACHE, "models--stabilityai--stable-diffusion-2-1") | ||
| MODEL_ID = "stabilityai/stable-diffusion-2-1" | ||
| SD_URL = "https://weights.replicate.delivery/default/stable-diffusion/stable-diffusion-2-1.tar" | ||
|
|
||
| SAFETY_CACHE = os.path.join( | ||
| MODEL_CACHE, "models--CompVis--stable-diffusion-safety-checker" | ||
| ) | ||
| SAFETY_MODEL_ID = "CompVis/stable-diffusion-safety-checker" | ||
| SAFETY_URL = "https://weights.replicate.delivery/default/stable-diffusion/stable-diffusion-safety-checker.tar" | ||
|
|
||
|
|
||
| class Predictor(BasePredictor): | ||
| def setup(self): | ||
| """Load the model into memory to make running multiple predictions efficient""" | ||
|
|
||
| print("Loading pipeline...") | ||
| WeightsDownloader.download_if_not_exists(SAFETY_URL, SAFETY_CACHE) | ||
| safety_checker = StableDiffusionSafetyChecker.from_pretrained( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably include a revision, same as https://github.com/replicate/cog-deepfloyd-if/pull/2 |
||
| SAFETY_MODEL_ID, | ||
| cache_dir=MODEL_CACHE, | ||
| local_files_only=True, | ||
| ) | ||
|
|
||
| WeightsDownloader.download_if_not_exists(SD_URL, SD_MODEL_CACHE) | ||
| self.pipe = StableDiffusionPipeline.from_pretrained( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should probably include a revision |
||
| MODEL_ID, | ||
| safety_checker=safety_checker, | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import os | ||
| import subprocess | ||
| import time | ||
|
|
||
|
|
||
| class WeightsDownloader: | ||
| @staticmethod | ||
| def download_if_not_exists(url, dest): | ||
| if not os.path.exists(dest): | ||
| WeightsDownloader.download(url, dest) | ||
|
|
||
| @staticmethod | ||
| def download(url, dest): | ||
| start = time.time() | ||
| print("downloading url: ", url) | ||
| print("downloading to: ", dest) | ||
| subprocess.check_call(["pget", "-x", url, dest], close_fds=False) | ||
| print("downloading took: ", time.time() - start) |
Uh oh!
There was an error while loading. Please reload this page.