Repository: stable-diffusion-webui
Issue: [Bug]: Training Large Resolution Embeddings Resulting in the "`Error:DArray dimension length > INT_MAX`" Error
Labels: bug-report,platform:mac

### Is there an existing issue for this?

- [X] I have searched the existing issues and checked the recent builds/commits

### What happened?

When training Stable Diffusion Commits 22bcc7b with images downscaled by Stable Diffusion to the maximum resolution of 2048x2048 available on my Mac Mini M2 Pro with 32 GB of RAM, Stable Diffusion encounters a `Connection errored out` error in its web browser interface in like 2 seconds after clicking the „Train Embedding” button. At the same time, the error accompanying this and printed out in the Terminal, which seems to be linked directly to the resolution of the images trained with, reads as follows:

```
706: failed assertion `[MPSTemporaryNDArray initWithDevice:descriptor:] Error:DArray dimension length > INT_MAX
zsh: abort      bash webui.sh
```

The settings when initiating the training are as follows:

Stable Diffusion Checkpoint/Model: v1-5-pruned-emaonly.ckpt [cc6cb27103]
Embedding Learning rate: 0.005
Gradient Clipping: disabled
Batch size: 1
Gradient accumulation steps: 1
Prompt template: subject_filewords.txt
Width: 2048
Height: 2048
Do not resize images: Unchecked
Max steps: 100000
Save an image to log directory every N steps, 0 to disable: 500
Save a copy of embedding to log directory every N steps, 0 to disable: 500
Use PNG alpha channel as loss weight: Unchecked
Save images with embedding in PNG chunks: Checked
Read parameters (prompt, etc...) from txt2img tab when making previews: Unchecked
Shuffle tags by ',' when creating prompts: Unchecked
Drop out tags when creating prompts: 0
Choose latent sampling method: once

![Connection errored out](https://user-images.githubusercontent.com/131956289/235297569-8a816352-d7a1-4535-93a5-dfed117d5751.png)

![Terminal Error](https://user-images.githubusercontent.com/131956289/235345461-69df4c35-2112-4ba2-aac4-eb6c288dfac5.png)

### Steps to reproduce the problem

1. Select a checkpoint/model of your choice.

2. Go to the Training tab in the Stable Diffusion Commits 22bcc7b web browser interface.

3. Select an Embedding of your choice for training.

4. Do not select any Hypernetwork for training.

5. Point Stable Diffusion to your directory with a decent number of your input images (in my case it was 487 images) at the resolution of 2048x2048 (or the maximum resolution available for Stable Diffusion on your computer).

6. Leave all the settings at their defaults, except for the resolution and prompt template.

7. Set the resolution to 2048x2048 (or the maximum resolution available for Stable Diffusion on your computer), and the prompt template to subject_filewords.txt.

8. Click the „Train Embedding” button an see if the error occurs.

### What should have happened?

The training process should have commenced and completed with either no errors, or at least there should occur such errors, which would not result in the training process crashing and not completing.

### Commit where the problem happens

https://github.com/AUTOMATIC1111/stable-diffusion-webui/commit/22bcc7b

### What platforms do you use to access the UI ?

MacOS

### What browsers do you use to access the UI ?

Apple Safari

### Command Line Arguments

```Shell
No
```


### List of extensions

No

### Console logs

```Shell
Last login: Sun Apr 30 10:38:31 on ttys000
hubert@Huberts-Mac-Mini ~ % cd stable-diffusion-webui 
hubert@Huberts-Mac-Mini stable-diffusion-webui % bash webui.sh

################################################################
Install script for stable-diffusion + Web UI
Tested on Debian 11 (Bullseye)
################################################################

################################################################
Running on hubert user
################################################################

################################################################
Repo already cloned, using it as install directory
################################################################

################################################################
Create and activate python venv
################################################################

################################################################
Launching launch.py...
################################################################
Python 3.10.11 (main, Apr  7 2023, 07:24:53) [Clang 14.0.0 (clang-1400.0.29.202)]
Commit hash: 22bcc7be428c94e9408f589966c2040187245d81
Installing requirements for Web UI
Launching Web UI with arguments: --skip-torch-cuda-test --upcast-sampling --no-half-vae --use-cpu interrogate
Warning: caught exception 'Torch not compiled with CUDA enabled', memory monitor disabled
No module 'xformers'. Proceeding without it.
==============================================================================
You are running torch 1.12.1.
The program is tested to work with torch 1.13.1.
To reinstall the desired version, run with commandline flag --reinstall-torch.
Beware that this will cause a lot of large files to be downloaded, as well as
there are reports of issues with training tab on the latest version.

Use --skip-version-check commandline argument to disable this check.
==============================================================================
Loading weights [cc6cb27103] from /Users/hubert/stable-diffusion-webui/models/Stable-diffusion/v1-5-pruned-emaonly.ckpt
Creating model from config: /Users/hubert/stable-diffusion-webui/configs/v1-inference.yaml
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
Applying cross attention optimization (InvokeAI).
Textual inversion embeddings loaded(1): Landscapes
Model loaded in 2.4s (load weights from disk: 0.6s, create model: 0.6s, apply weights to model: 0.4s, apply half(): 0.3s, move model to device: 0.4s).
Running on local URL:  http://127.0.0.1:7860

To create a public link, set `share=True` in `launch()`.
Startup time: 5.1s (import torch: 0.8s, import gradio: 0.6s, import ldm: 0.2s, other imports: 0.6s, load scripts: 0.2s, load SD checkpoint: 2.5s, create ui: 0.1s).
Training at rate of 0.005 until step 100000
Preparing dataset...
  0%|                                                  | 0/1026 [00:00<?, ?it/s]/AppleInternal/Library/BuildRoots/9941690d-bcf7-11ed-a645-863efbbaf80d/Library/Caches/com.apple.xbs/Sources/MetalPerformanceShaders/MPSCore/Types/MPSNDArray.mm:706: failed assertion `[MPSTemporaryNDArray initWithDevice:descriptor:] Error: NDArray dimension length > INT_MAX'
zsh: abort      bash webui.sh
hubert@Huberts-Mac-Mini stable-diffusion-webui % /opt/homebrew/Cellar/python@3.10/3.10.11/Frameworks/Python.framework/Versions/3.10/lib/python3.10/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 1 leaked semaphore objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '
```


### Additional information

_No response_