mirror of
https://github.com/Stability-AI/generative-models.git
synced 2025-12-22 15:54:21 +01:00
Set up Python packaging (#17)
* Sort .gitignore; add dist and *.py[cod] * Use pyproject.toml + Hatch instead of setup.py Sibling of https://github.com/Stability-AI/stablediffusion/pull/269 * Add packaging documentation
This commit is contained in:
10
.gitignore
vendored
10
.gitignore
vendored
@@ -1,7 +1,9 @@
|
||||
*.egg-info
|
||||
*.py[cod]
|
||||
.pt13
|
||||
.pt2
|
||||
.pt2_2
|
||||
.pt13
|
||||
*.egg-info
|
||||
build
|
||||
/checkpoints
|
||||
/dist
|
||||
/outputs
|
||||
/checkpoints
|
||||
build
|
||||
|
||||
17
README.md
17
README.md
@@ -76,6 +76,23 @@ pip3 install wheel
|
||||
pip3 install -r requirements_pt2.txt
|
||||
```
|
||||
|
||||
## Packaging
|
||||
|
||||
This repository uses PEP 517 compliant packaging using [Hatch](https://hatch.pypa.io/latest/).
|
||||
|
||||
To build a distributable wheel, install `hatch` and run `hatch build`
|
||||
(specifying `-t wheel` will skip building a sdist, which is not necessary).
|
||||
|
||||
```
|
||||
pip install hatch
|
||||
hatch build -t wheel
|
||||
```
|
||||
|
||||
You will find the built package in `dist/`. You can install the wheel with `pip install dist/*.whl`.
|
||||
|
||||
Note that the package does **not** currently specify dependencies; you will need to install the required packages,
|
||||
depending on your use case and PyTorch version, manually.
|
||||
|
||||
## Inference:
|
||||
|
||||
We provide a [streamlit](https://streamlit.io/) demo for text-to-image and image-to-image sampling in `scripts/demo/sampling.py`. The following models are currently supported:
|
||||
|
||||
34
pyproject.toml
Normal file
34
pyproject.toml
Normal file
@@ -0,0 +1,34 @@
|
||||
[build-system]
|
||||
requires = ["hatchling"]
|
||||
build-backend = "hatchling.build"
|
||||
|
||||
[project]
|
||||
name = "sgm"
|
||||
dynamic = ["version"]
|
||||
description = "Stability Generative Models"
|
||||
readme = "README.md"
|
||||
license-files = { paths = ["LICENSE"] }
|
||||
requires-python = ">=3.8"
|
||||
|
||||
[project.urls]
|
||||
Homepage = "https://github.com/Stability-AI/generative-models"
|
||||
|
||||
[tool.hatch.version]
|
||||
path = "sgm/__init__.py"
|
||||
|
||||
[tool.hatch.build]
|
||||
# This needs to be explicitly set so the configuration files
|
||||
# grafted into the `sgm` directory get included in the wheel's
|
||||
# RECORD file.
|
||||
include = [
|
||||
"sgm",
|
||||
]
|
||||
# The force-include configurations below make Hatch copy
|
||||
# the configs/ directory (containing the various YAML files required
|
||||
# to generatively model) into the source distribution and the wheel.
|
||||
|
||||
[tool.hatch.build.targets.sdist.force-include]
|
||||
"./configs" = "sgm/configs"
|
||||
|
||||
[tool.hatch.build.targets.wheel.force-include]
|
||||
"./configs" = "sgm/configs"
|
||||
13
setup.py
13
setup.py
@@ -1,13 +0,0 @@
|
||||
from setuptools import find_packages, setup
|
||||
|
||||
setup(
|
||||
name="sgm",
|
||||
version="0.0.1",
|
||||
packages=find_packages(),
|
||||
python_requires=">=3.8",
|
||||
py_modules=["sgm"],
|
||||
description="Stability Generative Models",
|
||||
long_description=open("README.md", "r", encoding="utf-8").read(),
|
||||
long_description_content_type="text/markdown",
|
||||
url="https://github.com/Stability-AI/generative-models",
|
||||
)
|
||||
@@ -1,3 +1,5 @@
|
||||
from .data import StableDataModuleFromConfig
|
||||
from .models import AutoencodingEngine, DiffusionEngine
|
||||
from .util import instantiate_from_config
|
||||
from .util import instantiate_from_config, get_configs_path
|
||||
|
||||
__version__ = "0.0.1"
|
||||
|
||||
18
sgm/util.py
18
sgm/util.py
@@ -229,3 +229,21 @@ def load_model_from_config(config, ckpt, verbose=True, freeze=True):
|
||||
|
||||
model.eval()
|
||||
return model
|
||||
|
||||
|
||||
def get_configs_path() -> str:
|
||||
"""
|
||||
Get the `configs` directory.
|
||||
For a working copy, this is the one in the root of the repository,
|
||||
but for an installed copy, it's in the `sgm` package (see pyproject.toml).
|
||||
"""
|
||||
this_dir = os.path.dirname(__file__)
|
||||
candidates = (
|
||||
os.path.join(this_dir, "configs"),
|
||||
os.path.join(this_dir, "..", "configs"),
|
||||
)
|
||||
for candidate in candidates:
|
||||
candidate = os.path.abspath(candidate)
|
||||
if os.path.isdir(candidate):
|
||||
return candidate
|
||||
raise FileNotFoundError(f"Could not find SGM configs in {candidates}")
|
||||
|
||||
Reference in New Issue
Block a user