Skip to content
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

requirements: Adopt pip compile #195

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/test-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
requirements-file: ["pt2", "pt13"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -23,5 +22,5 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements/${{ matrix.requirements-file }}.txt
pip install .
pip install -r requirements.txt
pip install .
4 changes: 1 addition & 3 deletions .github/workflows/test-inference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ name: Test inference

on:
pull_request:
push:
branches:
- main
push: {}

jobs:
test:
Expand Down
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
*.py[cod]

# envs
.pt13
.pt2
.venv

# directories
/checkpoints
/dist
/outputs
/build
/src
/src
61 changes: 61 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Contains helpful make targets for development
UNAME_S?=$(shell uname -s)
REQUIREMENTS_FILE?=requirements.txt
CUDA_DOCKER_VERSION?=11.8.0
ifeq ($(UNAME_S), Darwin)
REQUIREMENTS_FILE=requirements-macos.txt
endif

.venv: requirements/requirements.in ## Create a virtual environment and install dependencies
python3 -m venv --clear .venv
.venv/bin/pip install wheel pip-tools
.venv/bin/pip-compile requirements/requirements.in --output-file=requirements/$(REQUIREMENTS_FILE)
.venv/bin/pip install -r $(REQUIREMENTS_FILE)

.PHONY: compile-requirements
compile-requirements: .venv ## Compile requirements.in to requirements.txt
.venv/bin/pip-compile requirements/requirements.in --output-file=requirements/$(REQUIREMENTS_FILE)

.PHONY: compile-requirements-docker
compile-requirements-docker: ## Compile requirements.in to requirements.txt (in a docker container)
# Build the docker image
docker build --platform=linux/amd64 \
--build-arg CUDA_DOCKER_VERSION=$(CUDA_DOCKER_VERSION) \
--target final \
-t sd-compile-requirements \
-f scripts/Dockerfile.compile-requirements \
.
# Run the docker image (to copy the requirements.txt file out)
docker run --platform=linux/amd64 \
--gpus all \
-v $(PWD):/app \
-t sd-compile-requirements \
cp /tmp/requirements.txt requirements/$(REQUIREMENTS_FILE)

.PHONY: test
test: test-inference ## Run tests

.PHONY: test-inference
test-inference: .venv ## Run inference tests
.venv/bin/pytest -v tests/inference/test_inference.py

.PHONY: test-inference-docker
test-inference-docker: ## Run inference tests (in a docker container)
# Build the docker image
docker build --platform=linux/amd64 \
--build-arg CUDA_DOCKER_VERSION=$(CUDA_DOCKER_VERSION) \
--target test-inference \
-t sd-test-inference \
-f scripts/Dockerfile.compile-requirements \
.
# Run the docker image
docker run --platform=linux/amd64 \
-v $(PWD):/app \
-t sd-test-inference

.PHONY: clean
clean: ## Remove the virtual environment
@rm -rf .venv

.DELETE_ON_ERROR: ## Configure make to delete the target of a rule if it has an error

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ This is assuming you have navigated to the `generative-models` root after clonin

```shell
# install required packages from pypi
python3 -m venv .pt2
source .pt2/bin/activate
pip3 install -r requirements/pt2.txt
python3 -m venv .venv
source .venv/bin/activate
pip3 install -r requirements.txt
```

#### 3. Install `sgm`
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ dependencies = [

[tool.hatch.envs.ci.scripts]
test-inference = [
"pip install torch==2.0.1+cu118 torchvision==0.15.2+cu118 torchaudio==2.0.2+cu118 --index-url https://download.pytorch.org/whl/cu118",
"pip install -r requirements/pt2.txt",
"pip install -r requirements.txt",
"pytest -v tests/inference/test_inference.py {args}",
]
5 changes: 3 additions & 2 deletions requirements/pt2.txt → requirements/requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--find-links https://download.pytorch.org/whl/torch_stable.html
black==23.7.0
chardet==5.1.0
clip @ git+https://github.com/openai/CLIP.git
Expand Down Expand Up @@ -31,9 +32,9 @@ torchmetrics>=1.0.1
torchvision>=0.15.2
tqdm>=4.65.0
transformers==4.19.1
triton==2.0.0
triton==2.0.0; sys_platform == "linux"
urllib3<1.27,>=1.25.4
wandb>=0.15.6
webdataset>=0.2.33
wheel>=0.41.0
xformers>=0.0.20
xformers
Loading