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

Helpers + Streamlit refactor #102

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open

Helpers + Streamlit refactor #102

wants to merge 57 commits into from

Conversation

palp
Copy link
Member

@palp palp commented Aug 3, 2023

Updates to api/helper functions:

  • Adds Txt2NoisyDiscretizationWrapper to helpers and creates a function to apply discretization wrappers conditionally.
  • Align defaults with streamlit demo
  • Updates SamplingPipeline constructor to allow passing a custom model_spec, and improve default paths behavior
  • Support "Low VRAM Mode" via a wrapper class that moves models as needed automatically
  • Redo deduplication work from Add inference helpers & tests #57
  • Streamlit refactor #105 to finish the deduplication between inference and streamlit code. Prior to refactoring I confirmed 1:1 reproduction between the two in this branch.
  • Bump version to 0.1.1

@palp palp requested a review from a team as a code owner August 7, 2023 02:21
palp and others added 2 commits August 6, 2023 19:22
* initial streamlit refactoring pass

* cleanup and fixes

* fix refiner strength

* Modify params correctly

* fix exception
@palp palp requested a review from benjaminaubin August 7, 2023 03:26
@palp palp changed the title Helpers fixes Helpers + Streamlit refactor Aug 7, 2023
@palp
Copy link
Member Author

palp commented Aug 7, 2023

I've tested streamlit and all seems to be working well there still.

@palp palp removed the request for review from benjaminaubin August 7, 2023 18:14
Copy link

@ct-777 ct-777 left a comment

Choose a reason for hiding this comment

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

The PR contains many formatting. Is it completely done by pylint? If not, can you show your VSCode Python format setting (setting.json) and add to the repo? I hope people can follow the same style.

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

palp commented Aug 10, 2023

Re-tested streamlit and made some fixes, I've also reverted to a device parameter in SamplingPipeline that can create a DeviceModelManager for you, to simplify basic use cases.

sgm/inference/api.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
Comment on lines 243 to 248
c[k], uc[k] = map(
lambda y: y[k][: math.prod(num_samples)].to(device), (c, uc)
lambda y: y[k][: math.prod(num_samples)].to(
device_manager.device
),
(c, uc),
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly, this .map abomination should just be

Suggested change
c[k], uc[k] = map(
lambda y: y[k][: math.prod(num_samples)].to(device), (c, uc)
lambda y: y[k][: math.prod(num_samples)].to(
device_manager.device
),
(c, uc),
)
c[k] = c[k][: math.prod(num_samples)].to(device_manager.device)
uc[k] = uc[k][: math.prod(num_samples)].to(device_manager.device)

(and as discussed (and implemented) before, num_samples being a list one needs to math.prod on doesn't make any sense, but that's probably beyond the scope of this PR.)

sgm/inference/helpers.py Outdated Show resolved Hide resolved
Comment on lines +379 to +381
c[k], uc[k] = map(
lambda y: y[k][:num_samples].to(device_manager.device), (c, uc)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
c[k], uc[k] = map(
lambda y: y[k][:num_samples].to(device_manager.device), (c, uc)
)
c[k] = c[k][:num_samples].to(device_manager.device)
uc[k] = uc[k][:num_samples].to(device_manager.device)

(funny how num_samples is an int here 😁)

@akx
Copy link
Contributor

akx commented Sep 4, 2023

Would be nice to get this squashed in so I could again rebase my PRs ;-)

@akx
Copy link
Contributor

akx commented Nov 22, 2023

This'll probably need more fixing with the myriad of demo changes in 059d8e9 😞

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.

5 participants