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

ImportError: cannot import name 'randn_tensor' from 'diffusers.utils' #5025

Closed
Zerg-Overmind opened this issue Sep 14, 2023 · 5 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@Zerg-Overmind
Copy link

Describe the bug

In the newest version, whenever you run: from diffusers.utils import randn_tensor
you will get the error: importError: cannot import name 'randn_tensor' from 'diffusers.utils'
But you can fix this by adding "from .torch_utils import randn_tensor" to your pythonxx/site-packages/diffusers/utils/init.py" after installing the diffusers....

Reproduction

run "from diffusers.utils import randn_tensor" after installing the latest version

Logs

No response

System Info

diffusers 0.21.0

Who can help?

No response

@Zerg-Overmind Zerg-Overmind added the bug Something isn't working label Sep 14, 2023
@Zerg-Overmind Zerg-Overmind changed the title mportError: cannot import name 'randn_tensor' from 'diffusers.utils' ImportError: cannot import name 'randn_tensor' from 'diffusers.utils' Sep 14, 2023
@DN6
Copy link
Collaborator

DN6 commented Sep 14, 2023

Hi @Zerg-Overmind. We moved randn tensors out of utils to enable lazy imports. You can now access it via

from diffusers.utils.torch_utils import randn_tensor

@DN6 DN6 self-assigned this Sep 14, 2023
@sayakpaul
Copy link
Member

@DN6 seems to me we can close this issue no?

@DN6 DN6 closed this as completed Sep 14, 2023
emilk pushed a commit to rerun-io/rerun that referenced this issue Sep 28, 2023
Fixes import huggingface/diffusers#5025

<!--
Open the PR up as a draft until you feel it is ready for a proper
review.

Do not make PR:s from your own `main` branch, as that makes it difficult
for reviewers to add their own fixes.

Add any improvements to the branch as new commits to make it easier for
reviewers to follow the progress. All commits will be squashed to a
single commit once the PR is merged into `main`.

Make sure you mention any issues that this PR closes in the description,
as well as any other related issues.

To get an auto-generated PR description you can put "copilot:summary" or
"copilot:walkthrough" anywhere.
-->

### What

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [ ] I have tested [demo.rerun.io](https://demo.rerun.io/pr/{{
pr.number }}) (if applicable)

- [PR Build Summary](https://build.rerun.io/pr/{{ pr.number }})
- [Docs preview](https://rerun.io/preview/{{ pr.commit }}/docs)
<!--DOCS-PREVIEW-->
- [Examples preview](https://rerun.io/preview/{{ pr.commit }}/examples)
<!--EXAMPLES-PREVIEW-->
- [Recent benchmark results](https://ref.rerun.io/dev/bench/)
- [Wasm size tracking](https://ref.rerun.io/dev/sizes/)
@johnowhitaker
Copy link
Contributor

@DN6 @sayakpaul FYI this breaks a few things - for e.g. I just tried to use TRL for something and get an error thanks to this:

----> [4](vscode-notebook-cell://ssh-remote%2Brig2/home/jonathan/kaggle_llm/sft_letter.ipynb#W0sdnNjb2RlLXJlbW90ZQ%3D%3D?line=3) from trl import SFTTrainer, DataCollatorForCompletionOnlyLM
      [5](vscode-notebook-cell://ssh-remote%2Brig2/home/jonathan/kaggle_llm/sft_letter.ipynb#W0sdnNjb2RlLXJlbW90ZQ%3D%3D?line=4) from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, TrainingArguments

File [~/miniconda3/envs/cuda11-7/lib/python3.8/site-packages/trl/__init__.py:7](https://vscode-remote+ssh-002dremote-002brig2.vscode-resource.vscode-cdn.net/home/jonathan/kaggle_llm/~/miniconda3/envs/cuda11-7/lib/python3.8/site-packages/trl/__init__.py:7)
      5 from .core import set_seed
      6 from .environment import TextEnvironment, TextHistory
----> 7 from .extras import BestOfNSampler
      8 from .import_utils import is_diffusers_available, is_peft_available
      9 from .models import (
     10     AutoModelForCausalLMWithValueHead,
     11     AutoModelForSeq2SeqLMWithValueHead,
     12     PreTrainedModelWrapper,
     13     create_reference_model,
     14 )

File [~/miniconda3/envs/cuda11-7/lib/python3.8/site-packages/trl/extras/__init__.py:16](https://vscode-remote+ssh-002dremote-002brig2.vscode-resource.vscode-cdn.net/home/jonathan/kaggle_llm/~/miniconda3/envs/cuda11-7/lib/python3.8/site-packages/trl/extras/__init__.py:16)
      1 # flake8: noqa
      2 
      3 # Copyright 2022 The HuggingFace Team. All rights reserved.
   (...)
     14 # See the License for the specific language governing permissions and
     15 # limitations under the License.
---> 16 from .best_of_n_sampler import BestOfNSampler

File [~/miniconda3/envs/cuda11-7/lib/python3.8/site-packages/trl/extras/best_of_n_sampler.py:7](https://vscode-remote+ssh-002dremote-002brig2.vscode-resource.vscode-cdn.net/home/jonathan/kaggle_llm/~/miniconda3/envs/cuda11-7/lib/python3.8/site-packages/trl/extras/best_of_n_sampler.py:7)
      4 from transformers import GenerationConfig, PreTrainedTokenizer, PreTrainedTokenizerFast
      6 from ..core import set_seed
----> 7 from ..models import SUPPORTED_ARCHITECTURES, PreTrainedModelWrapper
     10 class BestOfNSampler(object):
     11     def __init__(
     12         self,
     13         model: PreTrainedModelWrapper,
   (...)
     20         generation_config: Optional[GenerationConfig] = None,
     21     ) -> None:

File [~/miniconda3/envs/cuda11-7/lib/python3.8/site-packages/trl/models/__init__.py:29](https://vscode-remote+ssh-002dremote-002brig2.vscode-resource.vscode-cdn.net/home/jonathan/kaggle_llm/~/miniconda3/envs/cuda11-7/lib/python3.8/site-packages/trl/models/__init__.py:29)
     25 from ..import_utils import is_diffusers_available
     28 if is_diffusers_available():
---> 29     from .modeling_sd_base import (
     30         DDPOPipelineOutput,
     31         DDPOSchedulerOutput,
     32         DDPOStableDiffusionPipeline,
     33         DefaultDDPOStableDiffusionPipeline,
     34     )

File [~/miniconda3/envs/cuda11-7/lib/python3.8/site-packages/trl/models/modeling_sd_base.py:27](https://vscode-remote+ssh-002dremote-002brig2.vscode-resource.vscode-cdn.net/home/jonathan/kaggle_llm/~/miniconda3/envs/cuda11-7/lib/python3.8/site-packages/trl/models/modeling_sd_base.py:27)
     25 from diffusers.models.attention_processor import LoRAAttnProcessor
     26 from diffusers.pipelines.stable_diffusion.pipeline_stable_diffusion import rescale_noise_cfg
---> 27 from diffusers.utils import randn_tensor
     30 @dataclass
     31 class DDPOPipelineOutput(object):
     32     """
     33     Output class for the diffusers pipeline to be finetuned with the DDPO trainer
     34 
   (...)
     42 
     43     """

ImportError: cannot import name 'randn_tensor' from 'diffusers.utils'

Might be worth looking through at least the HF libs looking for from diffusers.utils import randn_tensor and adding a fix that checks the diffusers version or something?

@osanseviero
Copy link
Contributor

Similar behaviour for me

from trl import SFTTrainer

File [~/miniconda3/envs/book/lib/python3.10/site-packages/trl/__init__.py:7](https://file+.vscode-resource.vscode-cdn.net/home/osanseviero/Desktop/workspace/genai/nbs/~/miniconda3/envs/book/lib/python3.10/site-packages/trl/__init__.py:7)
      5 from .core import set_seed
      6 from .environment import TextEnvironment, TextHistory
----> 7 from .extras import BestOfNSampler
      8 from .import_utils import is_diffusers_available, is_peft_available
      9 from .models import (
     10     AutoModelForCausalLMWithValueHead,
     11     AutoModelForSeq2SeqLMWithValueHead,
     12     PreTrainedModelWrapper,
     13     create_reference_model,
     14 )

File [~/miniconda3/envs/book/lib/python3.10/site-packages/trl/extras/__init__.py:16](https://file+.vscode-resource.vscode-cdn.net/home/osanseviero/Desktop/workspace/genai/nbs/~/miniconda3/envs/book/lib/python3.10/site-packages/trl/extras/__init__.py:16)
      1 # flake8: noqa
      2 
      3 # Copyright 2022 The HuggingFace Team. All rights reserved.
   (...)
...
   (...)
     42 
     43     """

ImportError: cannot import name 'randn_tensor' from 'diffusers.utils' (/home/osanseviero/miniconda3/envs/book/lib/python3.10/site-packages/diffusers/utils/__init__.py)

cc @lvwerra as well

@dage0127
Copy link

dage0127 commented Nov 6, 2023

pip install diffusers==0.18.0 works fine.

attashe added a commit to attashe/PixArt-alpha that referenced this issue Nov 6, 2023
Diffusers changed their API
huggingface/diffusers#5025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants