Skip to content

Conversation

@patrickvonplaten
Copy link
Contributor

@patrickvonplaten patrickvonplaten commented Oct 7, 2022

Co-Authored-By: Pi Esposito [email protected]

piEsposito and others added 30 commits September 5, 2022 12:04
@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Oct 7, 2022

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

@patrickvonplaten patrickvonplaten changed the title Pi esposito main [Low CPU memory] + device map Oct 7, 2022
class StableDiffusionSafetyChecker(PreTrainedModel):
config_class = CLIPConfig

_no_split_modules = ["CLIPEncoderLayer"]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

needed to allow to use device_map="auto"

@patrickvonplaten
Copy link
Contributor Author

This PR allows the following to be fully functional once the two following are merged:

@Thomas-MMJ
Copy link

looks like isort needs to be ran to make the linter happy.

import numpy as np
import torch

import accelerate

Choose a reason for hiding this comment

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

Need to sort the imports to make the linter happy, running isort locally gives this order,

import os
import random
import tempfile
import tracemalloc
import unittest

import accelerate
import numpy as np
import PIL
import torch

import transformers


import accelerate
import PIL
import transformers

Choose a reason for hiding this comment

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

see above comment for isort import grouping and ordering.

from diffusers.pipeline_utils import DiffusionPipeline
from diffusers.schedulers.scheduling_utils import SCHEDULER_CONFIG_NAME
from diffusers.utils import CONFIG_NAME, WEIGHTS_NAME, floats_tensor, load_image, slow, torch_device
from packaging import version

Choose a reason for hiding this comment

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

might also need to check with isort, locally it makes changes to their original commit also (makes the multiple item imports into a multiline tuple, and sorts PIL to the top), so my isort might be different than their config.

@patrickvonplaten
Copy link
Contributor Author

PRs on transformers and accelerate are merged! device_map="auto" should now work if using both transformers and accelerate on master.

Think we can merge here. @piEsposito, again very sorry about fiddeling with your PR so much - ok if we merge this PR (you'll be a co-author of it)?

@piEsposito
Copy link
Contributor

@patrickvonplaten no problem at all, things like that happen all the time. I really appreciate how you handled it and your kindness of keeping me as a co-author.

IMO you can merge this.

@patrickvonplaten patrickvonplaten merged commit fab1752 into main Oct 10, 2022
@patrickvonplaten patrickvonplaten deleted the piEspositoMain branch October 10, 2022 16:05
prathikr pushed a commit to prathikr/diffusers that referenced this pull request Oct 26, 2022
* add accelerate to load models with smaller memory footprint

* remove low_cpu_mem_usage as it is reduntant

* move accelerate init weights context to modelling utils

* add test to ensure results are the same when loading with accelerate

* add tests to ensure ram usage gets lower when using accelerate

* move accelerate logic to single snippet under modelling utils and remove it from configuration utils

* format code using to pass quality check

* fix imports with isor

* add accelerate to test extra deps

* only import accelerate if device_map is set to auto

* move accelerate availability check to diffusers import utils

* format code

* add device map to pipeline abstraction

* lint it to pass PR quality check

* fix class check to use accelerate when using diffusers ModelMixin subclasses

* use low_cpu_mem_usage in transformers if device_map is not available

* NoModuleLayer

* comment out tests

* up

* uP

* finish

* Update src/diffusers/pipelines/stable_diffusion/safety_checker.py

* finish

* uP

* make style

Co-authored-by: Pi Esposito <[email protected]>
yoonseokjin pushed a commit to yoonseokjin/diffusers that referenced this pull request Dec 25, 2023
* add accelerate to load models with smaller memory footprint

* remove low_cpu_mem_usage as it is reduntant

* move accelerate init weights context to modelling utils

* add test to ensure results are the same when loading with accelerate

* add tests to ensure ram usage gets lower when using accelerate

* move accelerate logic to single snippet under modelling utils and remove it from configuration utils

* format code using to pass quality check

* fix imports with isor

* add accelerate to test extra deps

* only import accelerate if device_map is set to auto

* move accelerate availability check to diffusers import utils

* format code

* add device map to pipeline abstraction

* lint it to pass PR quality check

* fix class check to use accelerate when using diffusers ModelMixin subclasses

* use low_cpu_mem_usage in transformers if device_map is not available

* NoModuleLayer

* comment out tests

* up

* uP

* finish

* Update src/diffusers/pipelines/stable_diffusion/safety_checker.py

* finish

* uP

* make style

Co-authored-by: Pi Esposito <[email protected]>
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