diff --git a/ui/media/js/auto-save.js b/ui/media/js/auto-save.js index 91a2d267..934b3f32 100644 --- a/ui/media/js/auto-save.js +++ b/ui/media/js/auto-save.js @@ -36,7 +36,7 @@ const SETTINGS_IDS_LIST = [ "save_to_disk", "diskPath", "sound_toggle", - "performance_level", + "vram_usage_level", "confirm_dangerous_actions", "metadata_output_format", "auto_save_settings", diff --git a/ui/media/js/main.js b/ui/media/js/main.js index 3a669b67..1e7269b4 100644 --- a/ui/media/js/main.js +++ b/ui/media/js/main.js @@ -602,7 +602,7 @@ function onTaskCompleted(task, reqBody, instance, outputContainer, stepUpdate) { Suggestions:
1. If you have set an initial image, please try reducing its dimension to ${MAX_INIT_IMAGE_DIMENSION}x${MAX_INIT_IMAGE_DIMENSION} or smaller.
- 2. Try picking a lower performance level in the 'Performance Level' setting (in the 'Settings' tab).
+ 2. Try picking a lower level in the 'GPU Memory Usage' setting (in the 'Settings' tab).
3. Try generating a smaller image.
` } } else { @@ -887,7 +887,7 @@ function getCurrentUserRequest() { width: parseInt(widthField.value), height: parseInt(heightField.value), // allow_nsfw: allowNSFWField.checked, - performance_level: perfLevelField.value, + vram_usage_level: vramUsageLevelField.value, //render_device: undefined, // Set device affinity. Prefer this device, but wont activate. use_stable_diffusion_model: stableDiffusionModelField.value, use_vae_model: vaeModelField.value, diff --git a/ui/media/js/parameters.js b/ui/media/js/parameters.js index 865f7bb5..93f1a266 100644 --- a/ui/media/js/parameters.js +++ b/ui/media/js/parameters.js @@ -94,18 +94,18 @@ var PARAMETERS = [ default: true, }, { - id: "performance_level", + id: "vram_usage_level", type: ParameterType.select, - label: "Performance Level", + label: "GPU Memory Usage", note: "Faster performance requires more GPU memory

" + + "Balanced: almost as fast as High, significantly lower GPU memory usage
" + "High: fastest, maximum GPU memory usage
" + - "Medium: decent speed, uses 1 GB more memory than Low
" + - "Low: slowest, for GPUs with 4 GB (or less) memory", + "Low: slowest, force-used for GPUs with 4 GB (or less) memory", icon: "fa-forward", - default: "high", + default: "balanced", options: [ + {value: "balanced", label: "Balanced"}, {value: "high", label: "High"}, - {value: "medium", label: "Medium"}, {value: "low", label: "Low"} ], }, @@ -227,7 +227,7 @@ function initParameters() { initParameters() -let perfLevelField = document.querySelector('#performance_level') +let vramUsageLevelField = document.querySelector('#vram_usage_level') let useCPUField = document.querySelector('#use_cpu') let autoPickGPUsField = document.querySelector('#auto_pick_gpus') let useGPUsField = document.querySelector('#use_gpus') diff --git a/ui/sd_internal/__init__.py b/ui/sd_internal/__init__.py index 5475c3a6..6f702749 100644 --- a/ui/sd_internal/__init__.py +++ b/ui/sd_internal/__init__.py @@ -6,7 +6,7 @@ class TaskData(BaseModel): request_id: str = None session_id: str = "session" save_to_disk_path: str = None - performance_level: str = "high" # or "low" or "medium" + vram_usage_level: str = "balanced" # or "low" or "medium" use_face_correction: str = None # or "GFPGANv1.3" use_upscale: str = None # or "RealESRGAN_x4plus" or "RealESRGAN_x4plus_anime_6B" diff --git a/ui/sd_internal/app.py b/ui/sd_internal/app.py index 7171e6c1..063069d2 100644 --- a/ui/sd_internal/app.py +++ b/ui/sd_internal/app.py @@ -110,7 +110,7 @@ def setConfig(config): except: log.error(traceback.format_exc()) -def save_to_config(ckpt_model_name, vae_model_name, hypernetwork_model_name, performance_level): +def save_to_config(ckpt_model_name, vae_model_name, hypernetwork_model_name, vram_usage_level): config = getConfig() if 'model' not in config: config['model'] = {} @@ -124,7 +124,7 @@ def save_to_config(ckpt_model_name, vae_model_name, hypernetwork_model_name, per if hypernetwork_model_name is None or hypernetwork_model_name == "": del config['model']['hypernetwork'] - config['performance_level'] = performance_level + config['vram_usage_level'] = vram_usage_level setConfig(config) diff --git a/ui/sd_internal/device_manager.py b/ui/sd_internal/device_manager.py index 8b5c49be..56508fad 100644 --- a/ui/sd_internal/device_manager.py +++ b/ui/sd_internal/device_manager.py @@ -128,7 +128,7 @@ def needs_to_force_full_precision(context): device_name = context.device_name.lower() return (('nvidia' in device_name or 'geforce' in device_name) and (' 1660' in device_name or ' 1650' in device_name)) or ('Quadro T2000' in device_name) -def get_max_perf_level(device): +def get_max_vram_usage_level(device): if device != 'cpu': _, mem_total = torch.cuda.mem_get_info(device) mem_total /= float(10**9) @@ -136,7 +136,7 @@ def get_max_perf_level(device): if mem_total < 4.5: return 'low' elif mem_total < 6.5: - return 'medium' + return 'balanced' return 'high' diff --git a/ui/sd_internal/model_manager.py b/ui/sd_internal/model_manager.py index 9c3320ea..56f1d9c0 100644 --- a/ui/sd_internal/model_manager.py +++ b/ui/sd_internal/model_manager.py @@ -25,9 +25,9 @@ DEFAULT_MODELS = { 'gfpgan': ['GFPGANv1.3'], 'realesrgan': ['RealESRGAN_x4plus'], } -PERF_LEVEL_TO_VRAM_OPTIMIZATIONS = { +VRAM_USAGE_LEVEL_TO_OPTIMIZATIONS = { + 'balanced': {'KEEP_FS_AND_CS_IN_CPU', 'SET_ATTENTION_STEP_TO_4'}, 'low': {'KEEP_ENTIRE_MODEL_IN_CPU'}, - 'medium': {'KEEP_FS_AND_CS_IN_CPU', 'SET_ATTENTION_STEP_TO_4'}, 'high': {}, } @@ -125,9 +125,24 @@ def resolve_model_paths(task_data: TaskData): if task_data.use_upscale: task_data.use_upscale = resolve_model_to_use(task_data.use_upscale, 'gfpgan') def set_vram_optimizations(context: Context): + def is_greater(a, b): # is a > b? + if a == "low": # b will be "low", "balanced" or "high" + return False + elif a == "balanced" and b != "low": # b will be "balanced" or "high" + return False + return True + config = app.getConfig() - perf_level = config.get('performance_level', device_manager.get_max_perf_level(context.device)) - vram_optimizations = PERF_LEVEL_TO_VRAM_OPTIMIZATIONS[perf_level] + + max_usage_level = device_manager.get_max_vram_usage_level(context.device) + vram_usage_level = config.get('vram_usage_level', 'balanced') + + if is_greater(vram_usage_level, max_usage_level): + log.error(f'Requested GPU Memory Usage level ({vram_usage_level}) is higher than what is ' + \ + f'possible ({max_usage_level}) on this device ({context.device}). Using "{max_usage_level}" instead') + vram_usage_level = max_usage_level + + vram_optimizations = VRAM_USAGE_LEVEL_TO_OPTIMIZATIONS[vram_usage_level] if vram_optimizations != context.vram_optimizations: context.vram_optimizations = vram_optimizations diff --git a/ui/sd_internal/task_manager.py b/ui/sd_internal/task_manager.py index 0780283d..094d853c 100644 --- a/ui/sd_internal/task_manager.py +++ b/ui/sd_internal/task_manager.py @@ -341,7 +341,7 @@ def get_devices(): 'name': torch.cuda.get_device_name(device), 'mem_free': mem_free, 'mem_total': mem_total, - 'max_perf_level': device_manager.get_max_perf_level(device), + 'max_vram_usage_level': device_manager.get_max_vram_usage_level(device), } # list the compatible devices diff --git a/ui/server.py b/ui/server.py index 11d3731a..59881975 100644 --- a/ui/server.py +++ b/ui/server.py @@ -134,7 +134,7 @@ def render(req: dict): render_req.init_image_mask = req.get('mask') # hack: will rename this in the HTTP API in a future revision - app.save_to_config(task_data.use_stable_diffusion_model, task_data.use_vae_model, task_data.use_hypernetwork_model, task_data.performance_level) + app.save_to_config(task_data.use_stable_diffusion_model, task_data.use_vae_model, task_data.use_hypernetwork_model, task_data.vram_usage_level) # enqueue the task new_task = task_manager.render(render_req, task_data)