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

Add inference helpers & tests #57

Merged
merged 50 commits into from
Jul 26, 2023
Merged

Add inference helpers & tests #57

merged 50 commits into from
Jul 26, 2023

Conversation

palp
Copy link
Member

@palp palp commented Jul 23, 2023

This change adds basic inference tests to cover the supported models & samplers, based on the streamlit demo. In service of this, a helper module was extracted from streamlit_helpers.py using kwargs in place of UI elements. A future PR could refactor the streamlit code to use it, avoiding the duplication of code and solidifying a source of truth for inference functions.

@palp palp marked this pull request as ready for review July 23, 2023 20:05
@akx
Copy link
Contributor

akx commented Jul 24, 2023

I also have a minimal txt2img example in a branch in my fork, but it would require some of my other PRs to get merged (see comments within). Could someone from Stability maybe take a look at them?

sgm/inference/helpers.py Outdated Show resolved Hide resolved
sgm/inference/helpers.py Outdated Show resolved Hide resolved
sgm/inference/helpers.py Outdated Show resolved Hide resolved
sgm/inference/helpers.py Outdated Show resolved Hide resolved
sgm/inference/helpers.py Outdated Show resolved Hide resolved
.github/workflows/test-inference.yml Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
.github/workflows/test-inference.yml Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
sgm/inference/helpers.py Show resolved Hide resolved
@benjaminaubin benjaminaubin self-requested a review July 25, 2023 06:50
Copy link
Contributor

@benjaminaubin benjaminaubin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@palp please make sure there is no duplication between

  • scripts/demo
  • sgm/inference
  • test/inference

Otherwise the other changes will be accepted.
Improvements and cleaning from other PRs should be worked out asap (thank you @akx)

.github/workflows/test-inference.yml Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
sgm/inference/helpers.py Show resolved Hide resolved
sgm/inference/helpers.py Outdated Show resolved Hide resolved
@palp palp mentioned this pull request Jul 25, 2023
Copy link
Contributor

@akx akx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments (but if this API's signatures can change in the future, some of them aren't interesting).

I'd maybe recommend also making top-level apis kwarg-only with (e.g.) do_img2img(*, img, ...) so user code can't mess up with e.g. parameter order.

sgm/inference/api.py Outdated Show resolved Hide resolved
sgm/inference/api.py Outdated Show resolved Hide resolved
sgm/inference/api.py Outdated Show resolved Hide resolved
sgm/inference/api.py Show resolved Hide resolved
sgm/inference/api.py Outdated Show resolved Hide resolved
sgm/inference/helpers.py Outdated Show resolved Hide resolved
tests/inference/test_inference.py Show resolved Hide resolved
sgm/inference/helpers.py Show resolved Hide resolved
sgm/inference/helpers.py Show resolved Hide resolved
sgm/inference/api.py Outdated Show resolved Hide resolved
@palp
Copy link
Member Author

palp commented Jul 26, 2023

Some comments (but if this API's signatures can change in the future, some of them aren't interesting).

I'd maybe recommend also making top-level apis kwarg-only with (e.g.) do_img2img(*, img, ...) so user code can't mess up with e.g. parameter order.

Some comments (but if this API's signatures can change in the future, some of them aren't interesting).

I'd maybe recommend also making top-level apis kwarg-only with (e.g.) do_img2img(*, img, ...) so user code can't mess up with e.g. parameter order.

Yeah, especially a lot of the "low level" functions are still mostly straight out of the streamlit demo and should get rewritten, but this is looking like the stopping point for this PR.

Copy link
Contributor

@benjaminaubin benjaminaubin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

@palp palp merged commit 931d7a3 into main Jul 26, 2023
6 checks passed
@palp palp deleted the palp/model-tests branch July 26, 2023 11:37
LinearFalcon pushed a commit to LinearFalcon/generative-models that referenced this pull request Jul 6, 2024
* Add inference helpers & tests

* Support testing with hatch

* fixes to hatch script

* add inference test action

* change workflow trigger

* widen trigger to test

* revert changes to workflow triggers

* Install local python in action

* Trigger on push again

* fix python version

* add CODEOWNERS and change triggers

* Report tests results

* update action versions

* format

* Fix typo and add refiner helper

* use a shared path loaded from a secret for checkpoints source

* typo fix

* Use device from input and remove duplicated code

* PR feedback

* fix call to load_model_from_config

* Move model to gpu

* Refactor helpers

* cleanup

* test refiner, prep for 1.0, align with metadata

* fix paths on second load

* deduplicate streamlit code

* filenames

* fixes

* add pydantic to requirements

* fix usage of `msg` in demo script

* remove double text

* run black

* fix streamlit sampling when returning latents

* extract function for streamlit output

* another fix for streamlit outputs

* fix img2img in streamlit

* Make fp16 optional and fix device param

* PR feedback

* fix dict cast for dataclass

* run black, update ci script

* cache pip dependencies on hosted runners, remove extra runs

* install package in ci env

* fix cache path

* PR cleanup

* one more cleanup

* don't cache, it filled up
SevanBrodjian pushed a commit to SevanBrodjian/sd-latent-exploration that referenced this pull request Aug 12, 2024
* Add inference helpers & tests

* Support testing with hatch

* fixes to hatch script

* add inference test action

* change workflow trigger

* widen trigger to test

* revert changes to workflow triggers

* Install local python in action

* Trigger on push again

* fix python version

* add CODEOWNERS and change triggers

* Report tests results

* update action versions

* format

* Fix typo and add refiner helper

* use a shared path loaded from a secret for checkpoints source

* typo fix

* Use device from input and remove duplicated code

* PR feedback

* fix call to load_model_from_config

* Move model to gpu

* Refactor helpers

* cleanup

* test refiner, prep for 1.0, align with metadata

* fix paths on second load

* deduplicate streamlit code

* filenames

* fixes

* add pydantic to requirements

* fix usage of `msg` in demo script

* remove double text

* run black

* fix streamlit sampling when returning latents

* extract function for streamlit output

* another fix for streamlit outputs

* fix img2img in streamlit

* Make fp16 optional and fix device param

* PR feedback

* fix dict cast for dataclass

* run black, update ci script

* cache pip dependencies on hosted runners, remove extra runs

* install package in ci env

* fix cache path

* PR cleanup

* one more cleanup

* don't cache, it filled up
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants