mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
Merge branch 'main' into patch-1
This commit is contained in:
commit
91acae30bf
57
.github/workflows/test-invoke-pip.yml
vendored
57
.github/workflows/test-invoke-pip.yml
vendored
@ -8,10 +8,11 @@ on:
|
|||||||
- 'ready_for_review'
|
- 'ready_for_review'
|
||||||
- 'opened'
|
- 'opened'
|
||||||
- 'synchronize'
|
- 'synchronize'
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
|
||||||
cancel-in-progress: true
|
cancel-in-progress: true
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
matrix:
|
matrix:
|
||||||
@ -62,28 +63,13 @@ jobs:
|
|||||||
# github-env: $env:GITHUB_ENV
|
# github-env: $env:GITHUB_ENV
|
||||||
name: ${{ matrix.pytorch }} on ${{ matrix.python-version }}
|
name: ${{ matrix.pytorch }} on ${{ matrix.python-version }}
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
|
env:
|
||||||
|
PIP_USE_PEP517: '1'
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
id: checkout-sources
|
id: checkout-sources
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: setup python
|
|
||||||
uses: actions/setup-python@v4
|
|
||||||
with:
|
|
||||||
python-version: ${{ matrix.python-version }}
|
|
||||||
|
|
||||||
- name: Set Cache-Directory Windows
|
|
||||||
if: runner.os == 'Windows'
|
|
||||||
id: set-cache-dir-windows
|
|
||||||
run: |
|
|
||||||
echo "CACHE_DIR=$HOME\invokeai\models" >> ${{ matrix.github-env }}
|
|
||||||
echo "PIP_NO_CACHE_DIR=1" >> ${{ matrix.github-env }}
|
|
||||||
|
|
||||||
- name: Set Cache-Directory others
|
|
||||||
if: runner.os != 'Windows'
|
|
||||||
id: set-cache-dir-others
|
|
||||||
run: echo "CACHE_DIR=$HOME/invokeai/models" >> ${{ matrix.github-env }}
|
|
||||||
|
|
||||||
- name: set test prompt to main branch validation
|
- name: set test prompt to main branch validation
|
||||||
if: ${{ github.ref == 'refs/heads/main' }}
|
if: ${{ github.ref == 'refs/heads/main' }}
|
||||||
run: echo "TEST_PROMPTS=tests/preflight_prompts.txt" >> ${{ matrix.github-env }}
|
run: echo "TEST_PROMPTS=tests/preflight_prompts.txt" >> ${{ matrix.github-env }}
|
||||||
@ -92,26 +78,29 @@ jobs:
|
|||||||
if: ${{ github.ref != 'refs/heads/main' }}
|
if: ${{ github.ref != 'refs/heads/main' }}
|
||||||
run: echo "TEST_PROMPTS=tests/validate_pr_prompt.txt" >> ${{ matrix.github-env }}
|
run: echo "TEST_PROMPTS=tests/validate_pr_prompt.txt" >> ${{ matrix.github-env }}
|
||||||
|
|
||||||
|
- name: setup python
|
||||||
|
uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: ${{ matrix.python-version }}
|
||||||
|
cache: pip
|
||||||
|
cache-dependency-path: pyproject.toml
|
||||||
|
|
||||||
- name: install invokeai
|
- name: install invokeai
|
||||||
env:
|
env:
|
||||||
PIP_EXTRA_INDEX_URL: ${{ matrix.extra-index-url }}
|
PIP_EXTRA_INDEX_URL: ${{ matrix.extra-index-url }}
|
||||||
run: >
|
run: >
|
||||||
pip3 install
|
pip3 install
|
||||||
--use-pep517
|
|
||||||
--editable=".[test]"
|
--editable=".[test]"
|
||||||
|
|
||||||
- name: run pytest
|
- name: run pytest
|
||||||
|
id: run-pytest
|
||||||
run: pytest
|
run: pytest
|
||||||
|
|
||||||
- name: Use Cached models
|
- name: set INVOKEAI_OUTDIR
|
||||||
id: cache-sd-model
|
run: >
|
||||||
uses: actions/cache@v3
|
python -c
|
||||||
env:
|
"import os;from ldm.invoke.globals import Globals;OUTDIR=os.path.join(Globals.root,str('outputs'));print(f'INVOKEAI_OUTDIR={OUTDIR}')"
|
||||||
cache-name: huggingface-models
|
>> ${{ matrix.github-env }}
|
||||||
with:
|
|
||||||
path: ${{ env.CACHE_DIR }}
|
|
||||||
key: ${{ env.cache-name }}
|
|
||||||
enableCrossOsArchive: true
|
|
||||||
|
|
||||||
- name: run invokeai-configure
|
- name: run invokeai-configure
|
||||||
id: run-preload-models
|
id: run-preload-models
|
||||||
@ -124,9 +113,8 @@ jobs:
|
|||||||
--full-precision
|
--full-precision
|
||||||
# can't use fp16 weights without a GPU
|
# can't use fp16 weights without a GPU
|
||||||
|
|
||||||
- name: Run the tests
|
- name: run invokeai
|
||||||
if: runner.os != 'Windows'
|
id: run-invokeai
|
||||||
id: run-tests
|
|
||||||
env:
|
env:
|
||||||
# Set offline mode to make sure configure preloaded successfully.
|
# Set offline mode to make sure configure preloaded successfully.
|
||||||
HF_HUB_OFFLINE: 1
|
HF_HUB_OFFLINE: 1
|
||||||
@ -137,10 +125,11 @@ jobs:
|
|||||||
--no-patchmatch
|
--no-patchmatch
|
||||||
--no-nsfw_checker
|
--no-nsfw_checker
|
||||||
--from_file ${{ env.TEST_PROMPTS }}
|
--from_file ${{ env.TEST_PROMPTS }}
|
||||||
|
--outdir ${{ env.INVOKEAI_OUTDIR }}/${{ matrix.python-version }}/${{ matrix.pytorch }}
|
||||||
|
|
||||||
- name: Archive results
|
- name: Archive results
|
||||||
id: archive-results
|
id: archive-results
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: results_${{ matrix.pytorch }}_${{ matrix.python-version }}
|
name: results
|
||||||
path: ${{ env.INVOKEAI_ROOT }}/outputs
|
path: ${{ env.INVOKEAI_OUTDIR }}
|
||||||
|
@ -122,6 +122,10 @@ class Generator:
|
|||||||
|
|
||||||
seed = self.new_seed()
|
seed = self.new_seed()
|
||||||
|
|
||||||
|
# Free up memory from the last generation.
|
||||||
|
if self.model.device.type == 'cuda':
|
||||||
|
torch.cuda.empty_cache()
|
||||||
|
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def sample_to_image(self,samples)->Image.Image:
|
def sample_to_image(self,samples)->Image.Image:
|
||||||
@ -240,7 +244,12 @@ class Generator:
|
|||||||
|
|
||||||
def get_perlin_noise(self,width,height):
|
def get_perlin_noise(self,width,height):
|
||||||
fixdevice = 'cpu' if (self.model.device.type == 'mps') else self.model.device
|
fixdevice = 'cpu' if (self.model.device.type == 'mps') else self.model.device
|
||||||
noise = torch.stack([rand_perlin_2d((height, width), (8, 8), device = self.model.device).to(fixdevice) for _ in range(self.latent_channels)], dim=0).to(self.model.device)
|
# limit noise to only the diffusion image channels, not the mask channels
|
||||||
|
input_channels = min(self.latent_channels, 4)
|
||||||
|
noise = torch.stack([
|
||||||
|
rand_perlin_2d((height, width),
|
||||||
|
(8, 8),
|
||||||
|
device = self.model.device).to(fixdevice) for _ in range(input_channels)], dim=0).to(self.model.device)
|
||||||
return noise
|
return noise
|
||||||
|
|
||||||
def new_seed(self):
|
def new_seed(self):
|
||||||
@ -341,3 +350,27 @@ class Generator:
|
|||||||
|
|
||||||
def torch_dtype(self)->torch.dtype:
|
def torch_dtype(self)->torch.dtype:
|
||||||
return torch.float16 if self.precision == 'float16' else torch.float32
|
return torch.float16 if self.precision == 'float16' else torch.float32
|
||||||
|
|
||||||
|
# returns a tensor filled with random numbers from a normal distribution
|
||||||
|
def get_noise(self,width,height):
|
||||||
|
device = self.model.device
|
||||||
|
# limit noise to only the diffusion image channels, not the mask channels
|
||||||
|
input_channels = min(self.latent_channels, 4)
|
||||||
|
if self.use_mps_noise or device.type == 'mps':
|
||||||
|
x = torch.randn([1,
|
||||||
|
input_channels,
|
||||||
|
height // self.downsampling_factor,
|
||||||
|
width // self.downsampling_factor],
|
||||||
|
dtype=self.torch_dtype(),
|
||||||
|
device='cpu').to(device)
|
||||||
|
else:
|
||||||
|
x = torch.randn([1,
|
||||||
|
input_channels,
|
||||||
|
height // self.downsampling_factor,
|
||||||
|
width // self.downsampling_factor],
|
||||||
|
dtype=self.torch_dtype(),
|
||||||
|
device=device)
|
||||||
|
if self.perlin > 0.0:
|
||||||
|
perlin_noise = self.get_perlin_noise(width // self.downsampling_factor, height // self.downsampling_factor)
|
||||||
|
x = (1-self.perlin)*x + self.perlin*perlin_noise
|
||||||
|
return x
|
||||||
|
@ -63,22 +63,3 @@ class Img2Img(Generator):
|
|||||||
shape = like.shape
|
shape = like.shape
|
||||||
x = (1-self.perlin)*x + self.perlin*self.get_perlin_noise(shape[3], shape[2])
|
x = (1-self.perlin)*x + self.perlin*self.get_perlin_noise(shape[3], shape[2])
|
||||||
return x
|
return x
|
||||||
|
|
||||||
def get_noise(self,width,height):
|
|
||||||
# copy of the Txt2Img.get_noise
|
|
||||||
device = self.model.device
|
|
||||||
if self.use_mps_noise or device.type == 'mps':
|
|
||||||
x = torch.randn([1,
|
|
||||||
self.latent_channels,
|
|
||||||
height // self.downsampling_factor,
|
|
||||||
width // self.downsampling_factor],
|
|
||||||
device='cpu').to(device)
|
|
||||||
else:
|
|
||||||
x = torch.randn([1,
|
|
||||||
self.latent_channels,
|
|
||||||
height // self.downsampling_factor,
|
|
||||||
width // self.downsampling_factor],
|
|
||||||
device=device)
|
|
||||||
if self.perlin > 0.0:
|
|
||||||
x = (1-self.perlin)*x + self.perlin*self.get_perlin_noise(width // self.downsampling_factor, height // self.downsampling_factor)
|
|
||||||
return x
|
|
||||||
|
@ -51,26 +51,4 @@ class Txt2Img(Generator):
|
|||||||
return make_image
|
return make_image
|
||||||
|
|
||||||
|
|
||||||
# returns a tensor filled with random numbers from a normal distribution
|
|
||||||
def get_noise(self,width,height):
|
|
||||||
device = self.model.device
|
|
||||||
# limit noise to only the diffusion image channels, not the mask channels
|
|
||||||
input_channels = min(self.latent_channels, 4)
|
|
||||||
if self.use_mps_noise or device.type == 'mps':
|
|
||||||
x = torch.randn([1,
|
|
||||||
input_channels,
|
|
||||||
height // self.downsampling_factor,
|
|
||||||
width // self.downsampling_factor],
|
|
||||||
dtype=self.torch_dtype(),
|
|
||||||
device='cpu').to(device)
|
|
||||||
else:
|
|
||||||
x = torch.randn([1,
|
|
||||||
input_channels,
|
|
||||||
height // self.downsampling_factor,
|
|
||||||
width // self.downsampling_factor],
|
|
||||||
dtype=self.torch_dtype(),
|
|
||||||
device=device)
|
|
||||||
if self.perlin > 0.0:
|
|
||||||
x = (1-self.perlin)*x + self.perlin*self.get_perlin_noise(width // self.downsampling_factor, height // self.downsampling_factor)
|
|
||||||
return x
|
|
||||||
|
|
||||||
|
@ -753,7 +753,7 @@ class ModelManager(object):
|
|||||||
return search_folder, found_models
|
return search_folder, found_models
|
||||||
|
|
||||||
def _choose_diffusers_vae(self, model_name:str, vae:str=None)->Union[dict,str]:
|
def _choose_diffusers_vae(self, model_name:str, vae:str=None)->Union[dict,str]:
|
||||||
|
|
||||||
# In the event that the original entry is using a custom ckpt VAE, we try to
|
# In the event that the original entry is using a custom ckpt VAE, we try to
|
||||||
# map that VAE onto a diffuser VAE using a hard-coded dictionary.
|
# map that VAE onto a diffuser VAE using a hard-coded dictionary.
|
||||||
# I would prefer to do this differently: We load the ckpt model into memory, swap the
|
# I would prefer to do this differently: We load the ckpt model into memory, swap the
|
||||||
@ -954,7 +954,7 @@ class ModelManager(object):
|
|||||||
def _has_cuda(self) -> bool:
|
def _has_cuda(self) -> bool:
|
||||||
return self.device.type == 'cuda'
|
return self.device.type == 'cuda'
|
||||||
|
|
||||||
def _diffuser_sha256(self,name_or_path:Union[str, Path])->Union[str,bytes]:
|
def _diffuser_sha256(self,name_or_path:Union[str, Path],chunksize=4096)->Union[str,bytes]:
|
||||||
path = None
|
path = None
|
||||||
if isinstance(name_or_path,Path):
|
if isinstance(name_or_path,Path):
|
||||||
path = name_or_path
|
path = name_or_path
|
||||||
@ -976,7 +976,8 @@ class ModelManager(object):
|
|||||||
for name in files:
|
for name in files:
|
||||||
count += 1
|
count += 1
|
||||||
with open(os.path.join(root,name),'rb') as f:
|
with open(os.path.join(root,name),'rb') as f:
|
||||||
sha.update(f.read())
|
while chunk := f.read(chunksize):
|
||||||
|
sha.update(chunk)
|
||||||
hash = sha.hexdigest()
|
hash = sha.hexdigest()
|
||||||
toc = time.time()
|
toc = time.time()
|
||||||
print(f' | sha256 = {hash} ({count} files hashed in','%4.2fs)' % (toc - tic))
|
print(f' | sha256 = {hash} ({count} files hashed in','%4.2fs)' % (toc - tic))
|
||||||
|
Loading…
Reference in New Issue
Block a user