Skip to content

Avoid negative strides for tensors #717

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

Merged
merged 3 commits into from
Oct 5, 2022
Merged

Avoid negative strides for tensors #717

merged 3 commits into from
Oct 5, 2022

Conversation

shirayu
Copy link
Contributor

@shirayu shirayu commented Oct 4, 2022

The original lines cause the following error for tensors.

At least one stride in the given numpy array is negative, and tensors with negative strides are not currently supported. (You can probably work around this by making a copy of your array  with array.copy().) 

The same operation is done here.

# Some schedulers like PNDM have timesteps as arrays
# It's more optimzed to move all timesteps to correct device beforehand
if torch.is_tensor(self.scheduler.timesteps):
timesteps_tensor = self.scheduler.timesteps.to(self.device)
else:
timesteps_tensor = torch.tensor(self.scheduler.timesteps.copy(), device=self.device)

(Probably related to #551 )

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Oct 4, 2022

The documentation is not available anymore as the PR was closed or merged.

@kashif
Copy link
Contributor

kashif commented Oct 4, 2022

@shirayu my feeling was that the imge2img pipeline would work without the need to convert the scheduler's timesteps to a torch tensor. If you have a look, the unet can take the time index as int and the callback also expects the time index to be an int. Can you kindly confirm if this pipeline works without the need to torch.tensor the timesteps?

@shirayu
Copy link
Contributor Author

shirayu commented Oct 4, 2022

@kashif Thank you for the comment.
I updated them (7f567ec) and they work fine.

@kashif
Copy link
Contributor

kashif commented Oct 4, 2022

while you are there you could fix the spelling of optimzed -> optimized and I believe the same would hold for the stable diffusion too? what would you say @anton-l ?

@patrickvonplaten
Copy link
Contributor

Running all slow tests now - if they pass, we're good to go!

@patrickvonplaten
Copy link
Contributor

Tests all pass -> merging!

@patrickvonplaten patrickvonplaten merged commit 60c9634 into huggingface:main Oct 5, 2022
@shirayu shirayu deleted the fix/timesteps_tensor branch October 5, 2022 10:58
prathikr pushed a commit to prathikr/diffusers that referenced this pull request Oct 26, 2022
* Avoid negative strides for tensors

* Changed not to make torch.tensor

* Removed a needless copy
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* Avoid negative strides for tensors

* Changed not to make torch.tensor

* Removed a needless copy
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