add an option to enable tiling image generation

This commit is contained in:
AUTOMATIC 2022-09-05 02:16:36 +03:00
parent a039878c0f
commit f91d0c3d19
3 changed files with 12 additions and 0 deletions

View File

@ -243,8 +243,13 @@ class EmbeddingsWithFixes(torch.nn.Module):
return inputs_embeds return inputs_embeds
def add_circular_option_to_conv_2d():
conv2d_constructor = torch.nn.Conv2d.__init__
def conv2d_constructor_circular(self, *args, **kwargs):
return conv2d_constructor(self, *args, padding_mode='circular', **kwargs)
torch.nn.Conv2d.__init__ = conv2d_constructor_circular
model_hijack = StableDiffusionModelHijack() model_hijack = StableDiffusionModelHijack()

View File

@ -30,6 +30,8 @@ parser.add_argument("--precision", type=str, help="evaluate at this precision",
parser.add_argument("--share", action='store_true', help="use share=True for gradio and make the UI accessible through their site (doesn't work for me but you might have better luck)") parser.add_argument("--share", action='store_true', help="use share=True for gradio and make the UI accessible through their site (doesn't work for me but you might have better luck)")
parser.add_argument("--esrgan-models-path", type=str, help="path to directory with ESRGAN models", default=os.path.join(script_path, 'ESRGAN')) parser.add_argument("--esrgan-models-path", type=str, help="path to directory with ESRGAN models", default=os.path.join(script_path, 'ESRGAN'))
parser.add_argument("--opt-split-attention", action='store_true', help="enable optimization that reduced vram usage by a lot for about 10% decrease in performance") parser.add_argument("--opt-split-attention", action='store_true', help="enable optimization that reduced vram usage by a lot for about 10% decrease in performance")
parser.add_argument("--tiling", action='store_true', help="causes the model to generate images that can be tiled")
cmd_opts = parser.parse_args() cmd_opts = parser.parse_args()
cpu = torch.device("cpu") cpu = torch.device("cpu")

View File

@ -140,6 +140,11 @@ try:
except Exception: except Exception:
pass pass
if cmd_opts.tiling:
# this has to be done before the model is loaded
modules.sd_hijack.add_circular_option_to_conv_2d()
sd_config = OmegaConf.load(cmd_opts.config) sd_config = OmegaConf.load(cmd_opts.config)
shared.sd_model = load_model_from_config(sd_config, cmd_opts.ckpt) shared.sd_model = load_model_from_config(sd_config, cmd_opts.ckpt)
shared.sd_model = (shared.sd_model if cmd_opts.no_half else shared.sd_model.half()) shared.sd_model = (shared.sd_model if cmd_opts.no_half else shared.sd_model.half())