We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Save UI defaults to settings.yaml Not working
### Describe the bug

When I try to activate few options and try  using Save UI defaults to settings.yaml it save empty settings.yaml



### Is there an existing issue for this?

- [X] I have searched the existing issues

### Reproduction

I check few options like in the image below:

![image](https://github.com/oobabooga/text-generation-webui/assets/4099839/1aee6ff0-abb3-4052-8831-a01fa9ef8e33)

and press  Save UI defaults to settings.yaml

close the termenal and start again and it goes back as if I did not set those options
Add to that when I check settings.yaml it is totally empty file


### Screenshot

_No response_

### Logs

```shell
it does not show any log
```


### System Info

```shell
Windows 11
I9 13900
Nvidia 4090
128GB RAM
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `modules/ui.py`
Content:
```
1 import copy
2 from pathlib import Path
3 
4 import gradio as gr
5 import torch
6 import yaml
7 from transformers import is_torch_xpu_available
8 
9 import extensions
10 from modules import shared
11 
12 with open(Path(__file__).resolve().parent / '../css/NotoSans/stylesheet.css', 'r') as f:
13     css = f.read()
14 with open(Path(__file__).resolve().parent / '../css/main.css', 'r') as f:
15     css += f.read()
16 with open(Path(__file__).resolve().parent / '../js/main.js', 'r') as f:
17     js = f.read()
18 with open(Path(__file__).resolve().parent / '../js/save_files.js', 'r') as f:
19     save_files_js = f.read()
20 with open(Path(__file__).resolve().parent / '../js/switch_tabs.js', 'r') as f:
21     switch_tabs_js = f.read()
22 with open(Path(__file__).resolve().parent / '../js/show_controls.js', 'r') as f:
23     show_controls_js = f.read()
24 with open(Path(__file__).resolve().parent / '../js/update_big_picture.js', 'r') as f:
25     update_big_picture_js = f.read()
26 
27 refresh_symbol = '🔄'
28 delete_symbol = '🗑️'
29 save_symbol = '💾'
30 
31 theme = gr.themes.Default(
32     font=['Noto Sans', 'Helvetica', 'ui-sans-serif', 'system-ui', 'sans-serif'],
33     font_mono=['IBM Plex Mono', 'ui-monospace', 'Consolas', 'monospace'],
34 ).set(
35     border_color_primary='#c5c5d2',
36     button_large_padding='6px 12px',
37     body_text_color_subdued='#484848',
38     background_fill_secondary='#eaeaea',
39     background_fill_primary='#fafafa',
40 )
41 
42 if Path("notification.mp3").exists():
43     audio_notification_js = "document.querySelector('#audio_notification audio')?.play();"
44 else:
45     audio_notification_js = ""
46 
47 
48 def list_model_elements():
49     elements = [
50         'loader',
51         'filter_by_loader',
52         'cpu_memory',
53         'auto_devices',
54         'disk',
55         'cpu',
56         'bf16',
57         'load_in_8bit',
58         'trust_remote_code',
59         'no_use_fast',
60         'use_flash_attention_2',
61         'load_in_4bit',
62         'compute_dtype',
63         'quant_type',
64         'use_double_quant',
65         'wbits',
66         'groupsize',
67         'model_type',
68         'pre_layer',
69         'triton',
70         'desc_act',
71         'no_inject_fused_attention',
72         'no_inject_fused_mlp',
73         'no_use_cuda_fp16',
74         'disable_exllama',
75         'disable_exllamav2',
76         'cfg_cache',
77         'no_flash_attn',
78         'num_experts_per_token',
79         'cache_8bit',
80         'cache_4bit',
81         'autosplit',
82         'threads',
83         'threads_batch',
84         'n_batch',
85         'no_mmap',
86         'mlock',
87         'no_mul_mat_q',
88         'n_gpu_layers',
89         'tensor_split',
90         'n_ctx',
91         'gpu_split',
92         'max_seq_len',
93         'compress_pos_emb',
94         'alpha_value',
95         'rope_freq_base',
96         'numa',
97         'logits_all',
98         'no_offload_kqv',
99         'row_split',
100         'tensorcores',
101         'streaming_llm',
102         'attention_sink_size',
103         'hqq_backend',
104     ]
105     if is_torch_xpu_available():
106         for i in range(torch.xpu.device_count()):
107             elements.append(f'gpu_memory_{i}')
108     else:
109         for i in range(torch.cuda.device_count()):
110             elements.append(f'gpu_memory_{i}')
111 
112     return elements
113 
114 
115 def list_interface_input_elements():
116     elements = [
117         'max_new_tokens',
118         'auto_max_new_tokens',
119         'max_tokens_second',
120         'prompt_lookup_num_tokens',
121         'seed',
122         'temperature',
123         'temperature_last',
124         'dynamic_temperature',
125         'dynatemp_low',
126         'dynatemp_high',
127         'dynatemp_exponent',
128         'smoothing_factor',
129         'smoothing_curve',
130         'top_p',
131         'min_p',
132         'top_k',
133         'typical_p',
134         'epsilon_cutoff',
135         'eta_cutoff',
136         'repetition_penalty',
137         'presence_penalty',
138         'frequency_penalty',
139         'repetition_penalty_range',
140         'encoder_repetition_penalty',
141         'no_repeat_ngram_size',
142         'do_sample',
143         'penalty_alpha',
144         'mirostat_mode',
145         'mirostat_tau',
146         'mirostat_eta',
147         'grammar_string',
148         'negative_prompt',
149         'guidance_scale',
150         'add_bos_token',
151         'ban_eos_token',
152         'custom_token_bans',
153         'sampler_priority',
154         'truncation_length',
155         'custom_stopping_strings',
156         'skip_special_tokens',
157         'stream',
158         'tfs',
159         'top_a',
160     ]
161 
162     # Chat elements
163     elements += [
164         'textbox',
165         'start_with',
166         'character_menu',
167         'history',
168         'name1',
169         'user_bio',
170         'name2',
171         'greeting',
172         'context',
173         'mode',
174         'custom_system_message',
175         'instruction_template_str',
176         'chat_template_str',
177         'chat_style',
178         'chat-instruct_command',
179     ]
180 
181     # Notebook/default elements
182     elements += [
183         'textbox-notebook',
184         'textbox-default',
185         'output_textbox',
186         'prompt_menu-default',
187         'prompt_menu-notebook',
188     ]
189 
190     # Model elements
191     elements += list_model_elements()
192 
193     return elements
194 
195 
196 def gather_interface_values(*args):
197     output = {}
198     for i, element in enumerate(list_interface_input_elements()):
199         output[element] = args[i]
200 
201     if not shared.args.multi_user:
202         shared.persistent_interface_state = output
203 
204     return output
205 
206 
207 def apply_interface_values(state, use_persistent=False):
208     if use_persistent:
209         state = shared.persistent_interface_state
210 
211     elements = list_interface_input_elements()
212     if len(state) == 0:
213         return [gr.update() for k in elements]  # Dummy, do nothing
214     else:
215         return [state[k] if k in state else gr.update() for k in elements]
216 
217 
218 def save_settings(state, preset, extensions_list, show_controls, theme_state):
219     output = copy.deepcopy(shared.settings)
220     exclude = ['name2', 'greeting', 'context', 'turn_template', 'truncation_length']
221     for k in state:
222         if k in shared.settings and k not in exclude:
223             output[k] = state[k]
224 
225     output['preset'] = preset
226     output['prompt-default'] = state['prompt_menu-default']
227     output['prompt-notebook'] = state['prompt_menu-notebook']
228     output['character'] = state['character_menu']
229     output['default_extensions'] = extensions_list
230     output['seed'] = int(output['seed'])
231     output['show_controls'] = show_controls
232     output['dark_theme'] = True if theme_state == 'dark' else False
233 
234     # Save extension values in the UI
235     for extension_name in extensions_list:
236         extension = getattr(extensions, extension_name).script
237         if hasattr(extension, 'params'):
238             params = getattr(extension, 'params')
239             for param in params:
240                 _id = f"{extension_name}-{param}"
241                 # Only save if different from default value
242                 if param not in shared.default_settings or params[param] != shared.default_settings[param]:
243                     output[_id] = params[param]
244 
245     # Do not save unchanged settings
246     for key in list(output.keys()):
247         if key in shared.default_settings and output[key] == shared.default_settings[key]:
248             output.pop(key)
249 
250     return yaml.dump(output, sort_keys=False, width=float("inf"))
251 
252 
253 def create_refresh_button(refresh_component, refresh_method, refreshed_args, elem_class, interactive=True):
254     """
255     Copied from https://github.com/AUTOMATIC1111/stable-diffusion-webui
256     """
257     def refresh():
258         refresh_method()
259         args = refreshed_args() if callable(refreshed_args) else refreshed_args
260 
261         return gr.update(**(args or {}))
262 
263     refresh_button = gr.Button(refresh_symbol, elem_classes=elem_class, interactive=interactive)
264     refresh_button.click(
265         fn=lambda: {k: tuple(v) if type(k) is list else v for k, v in refresh().items()},
266         inputs=[],
267         outputs=[refresh_component]
268     )
269 
270     return refresh_button
271
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/modules/ui.py b/modules/ui.py
--- a/modules/ui.py
+++ b/modules/ui.py
@@ -233,14 +233,16 @@
 
     # Save extension values in the UI
     for extension_name in extensions_list:
-        extension = getattr(extensions, extension_name).script
-        if hasattr(extension, 'params'):
-            params = getattr(extension, 'params')
-            for param in params:
-                _id = f"{extension_name}-{param}"
-                # Only save if different from default value
-                if param not in shared.default_settings or params[param] != shared.default_settings[param]:
-                    output[_id] = params[param]
+        extension = getattr(extensions, extension_name, None)
+        if extension:
+            extension = extension.script
+            if hasattr(extension, 'params'):
+                params = getattr(extension, 'params')
+                for param in params:
+                    _id = f"{extension_name}-{param}"
+                    # Only save if different from default value
+                    if param not in shared.default_settings or params[param] != shared.default_settings[param]:
+                        output[_id] = params[param]
 
     # Do not save unchanged settings
     for key in list(output.keys()):

{"golden_diff": "diff --git a/modules/ui.py b/modules/ui.py\n--- a/modules/ui.py\n+++ b/modules/ui.py\n@@ -233,14 +233,16 @@\n \n     # Save extension values in the UI\n     for extension_name in extensions_list:\n-        extension = getattr(extensions, extension_name).script\n-        if hasattr(extension, 'params'):\n-            params = getattr(extension, 'params')\n-            for param in params:\n-                _id = f\"{extension_name}-{param}\"\n-                # Only save if different from default value\n-                if param not in shared.default_settings or params[param] != shared.default_settings[param]:\n-                    output[_id] = params[param]\n+        extension = getattr(extensions, extension_name, None)\n+        if extension:\n+            extension = extension.script\n+            if hasattr(extension, 'params'):\n+                params = getattr(extension, 'params')\n+                for param in params:\n+                    _id = f\"{extension_name}-{param}\"\n+                    # Only save if different from default value\n+                    if param not in shared.default_settings or params[param] != shared.default_settings[param]:\n+                        output[_id] = params[param]\n \n     # Do not save unchanged settings\n     for key in list(output.keys()):\n", "issue": "Save UI defaults to settings.yaml Not working\n### Describe the bug\n\nWhen I try to activate few options and try  using Save UI defaults to settings.yaml it save empty settings.yaml\r\n\r\n\n\n### Is there an existing issue for this?\n\n- [X] I have searched the existing issues\n\n### Reproduction\n\nI check few options like in the image below:\r\n\r\n![image](https://github.com/oobabooga/text-generation-webui/assets/4099839/1aee6ff0-abb3-4052-8831-a01fa9ef8e33)\r\n\r\nand press  Save UI defaults to settings.yaml\r\n\r\nclose the termenal and start again and it goes back as if I did not set those options\r\nAdd to that when I check settings.yaml it is totally empty file\r\n\n\n### Screenshot\n\n_No response_\n\n### Logs\n\n```shell\nit does not show any log\n```\n\n\n### System Info\n\n```shell\nWindows 11\r\nI9 13900\r\nNvidia 4090\r\n128GB RAM\n```\n\n", "before_files": [{"content": "import copy\nfrom pathlib import Path\n\nimport gradio as gr\nimport torch\nimport yaml\nfrom transformers import is_torch_xpu_available\n\nimport extensions\nfrom modules import shared\n\nwith open(Path(__file__).resolve().parent / '../css/NotoSans/stylesheet.css', 'r') as f:\n    css = f.read()\nwith open(Path(__file__).resolve().parent / '../css/main.css', 'r') as f:\n    css += f.read()\nwith open(Path(__file__).resolve().parent / '../js/main.js', 'r') as f:\n    js = f.read()\nwith open(Path(__file__).resolve().parent / '../js/save_files.js', 'r') as f:\n    save_files_js = f.read()\nwith open(Path(__file__).resolve().parent / '../js/switch_tabs.js', 'r') as f:\n    switch_tabs_js = f.read()\nwith open(Path(__file__).resolve().parent / '../js/show_controls.js', 'r') as f:\n    show_controls_js = f.read()\nwith open(Path(__file__).resolve().parent / '../js/update_big_picture.js', 'r') as f:\n    update_big_picture_js = f.read()\n\nrefresh_symbol = '\ud83d\udd04'\ndelete_symbol = '\ud83d\uddd1\ufe0f'\nsave_symbol = '\ud83d\udcbe'\n\ntheme = gr.themes.Default(\n    font=['Noto Sans', 'Helvetica', 'ui-sans-serif', 'system-ui', 'sans-serif'],\n    font_mono=['IBM Plex Mono', 'ui-monospace', 'Consolas', 'monospace'],\n).set(\n    border_color_primary='#c5c5d2',\n    button_large_padding='6px 12px',\n    body_text_color_subdued='#484848',\n    background_fill_secondary='#eaeaea',\n    background_fill_primary='#fafafa',\n)\n\nif Path(\"notification.mp3\").exists():\n    audio_notification_js = \"document.querySelector('#audio_notification audio')?.play();\"\nelse:\n    audio_notification_js = \"\"\n\n\ndef list_model_elements():\n    elements = [\n        'loader',\n        'filter_by_loader',\n        'cpu_memory',\n        'auto_devices',\n        'disk',\n        'cpu',\n        'bf16',\n        'load_in_8bit',\n        'trust_remote_code',\n        'no_use_fast',\n        'use_flash_attention_2',\n        'load_in_4bit',\n        'compute_dtype',\n        'quant_type',\n        'use_double_quant',\n        'wbits',\n        'groupsize',\n        'model_type',\n        'pre_layer',\n        'triton',\n        'desc_act',\n        'no_inject_fused_attention',\n        'no_inject_fused_mlp',\n        'no_use_cuda_fp16',\n        'disable_exllama',\n        'disable_exllamav2',\n        'cfg_cache',\n        'no_flash_attn',\n        'num_experts_per_token',\n        'cache_8bit',\n        'cache_4bit',\n        'autosplit',\n        'threads',\n        'threads_batch',\n        'n_batch',\n        'no_mmap',\n        'mlock',\n        'no_mul_mat_q',\n        'n_gpu_layers',\n        'tensor_split',\n        'n_ctx',\n        'gpu_split',\n        'max_seq_len',\n        'compress_pos_emb',\n        'alpha_value',\n        'rope_freq_base',\n        'numa',\n        'logits_all',\n        'no_offload_kqv',\n        'row_split',\n        'tensorcores',\n        'streaming_llm',\n        'attention_sink_size',\n        'hqq_backend',\n    ]\n    if is_torch_xpu_available():\n        for i in range(torch.xpu.device_count()):\n            elements.append(f'gpu_memory_{i}')\n    else:\n        for i in range(torch.cuda.device_count()):\n            elements.append(f'gpu_memory_{i}')\n\n    return elements\n\n\ndef list_interface_input_elements():\n    elements = [\n        'max_new_tokens',\n        'auto_max_new_tokens',\n        'max_tokens_second',\n        'prompt_lookup_num_tokens',\n        'seed',\n        'temperature',\n        'temperature_last',\n        'dynamic_temperature',\n        'dynatemp_low',\n        'dynatemp_high',\n        'dynatemp_exponent',\n        'smoothing_factor',\n        'smoothing_curve',\n        'top_p',\n        'min_p',\n        'top_k',\n        'typical_p',\n        'epsilon_cutoff',\n        'eta_cutoff',\n        'repetition_penalty',\n        'presence_penalty',\n        'frequency_penalty',\n        'repetition_penalty_range',\n        'encoder_repetition_penalty',\n        'no_repeat_ngram_size',\n        'do_sample',\n        'penalty_alpha',\n        'mirostat_mode',\n        'mirostat_tau',\n        'mirostat_eta',\n        'grammar_string',\n        'negative_prompt',\n        'guidance_scale',\n        'add_bos_token',\n        'ban_eos_token',\n        'custom_token_bans',\n        'sampler_priority',\n        'truncation_length',\n        'custom_stopping_strings',\n        'skip_special_tokens',\n        'stream',\n        'tfs',\n        'top_a',\n    ]\n\n    # Chat elements\n    elements += [\n        'textbox',\n        'start_with',\n        'character_menu',\n        'history',\n        'name1',\n        'user_bio',\n        'name2',\n        'greeting',\n        'context',\n        'mode',\n        'custom_system_message',\n        'instruction_template_str',\n        'chat_template_str',\n        'chat_style',\n        'chat-instruct_command',\n    ]\n\n    # Notebook/default elements\n    elements += [\n        'textbox-notebook',\n        'textbox-default',\n        'output_textbox',\n        'prompt_menu-default',\n        'prompt_menu-notebook',\n    ]\n\n    # Model elements\n    elements += list_model_elements()\n\n    return elements\n\n\ndef gather_interface_values(*args):\n    output = {}\n    for i, element in enumerate(list_interface_input_elements()):\n        output[element] = args[i]\n\n    if not shared.args.multi_user:\n        shared.persistent_interface_state = output\n\n    return output\n\n\ndef apply_interface_values(state, use_persistent=False):\n    if use_persistent:\n        state = shared.persistent_interface_state\n\n    elements = list_interface_input_elements()\n    if len(state) == 0:\n        return [gr.update() for k in elements]  # Dummy, do nothing\n    else:\n        return [state[k] if k in state else gr.update() for k in elements]\n\n\ndef save_settings(state, preset, extensions_list, show_controls, theme_state):\n    output = copy.deepcopy(shared.settings)\n    exclude = ['name2', 'greeting', 'context', 'turn_template', 'truncation_length']\n    for k in state:\n        if k in shared.settings and k not in exclude:\n            output[k] = state[k]\n\n    output['preset'] = preset\n    output['prompt-default'] = state['prompt_menu-default']\n    output['prompt-notebook'] = state['prompt_menu-notebook']\n    output['character'] = state['character_menu']\n    output['default_extensions'] = extensions_list\n    output['seed'] = int(output['seed'])\n    output['show_controls'] = show_controls\n    output['dark_theme'] = True if theme_state == 'dark' else False\n\n    # Save extension values in the UI\n    for extension_name in extensions_list:\n        extension = getattr(extensions, extension_name).script\n        if hasattr(extension, 'params'):\n            params = getattr(extension, 'params')\n            for param in params:\n                _id = f\"{extension_name}-{param}\"\n                # Only save if different from default value\n                if param not in shared.default_settings or params[param] != shared.default_settings[param]:\n                    output[_id] = params[param]\n\n    # Do not save unchanged settings\n    for key in list(output.keys()):\n        if key in shared.default_settings and output[key] == shared.default_settings[key]:\n            output.pop(key)\n\n    return yaml.dump(output, sort_keys=False, width=float(\"inf\"))\n\n\ndef create_refresh_button(refresh_component, refresh_method, refreshed_args, elem_class, interactive=True):\n    \"\"\"\n    Copied from https://github.com/AUTOMATIC1111/stable-diffusion-webui\n    \"\"\"\n    def refresh():\n        refresh_method()\n        args = refreshed_args() if callable(refreshed_args) else refreshed_args\n\n        return gr.update(**(args or {}))\n\n    refresh_button = gr.Button(refresh_symbol, elem_classes=elem_class, interactive=interactive)\n    refresh_button.click(\n        fn=lambda: {k: tuple(v) if type(k) is list else v for k, v in refresh().items()},\n        inputs=[],\n        outputs=[refresh_component]\n    )\n\n    return refresh_button\n", "path": "modules/ui.py"}], "after_files": [{"content": "import copy\nfrom pathlib import Path\n\nimport gradio as gr\nimport torch\nimport yaml\nfrom transformers import is_torch_xpu_available\n\nimport extensions\nfrom modules import shared\n\nwith open(Path(__file__).resolve().parent / '../css/NotoSans/stylesheet.css', 'r') as f:\n    css = f.read()\nwith open(Path(__file__).resolve().parent / '../css/main.css', 'r') as f:\n    css += f.read()\nwith open(Path(__file__).resolve().parent / '../js/main.js', 'r') as f:\n    js = f.read()\nwith open(Path(__file__).resolve().parent / '../js/save_files.js', 'r') as f:\n    save_files_js = f.read()\nwith open(Path(__file__).resolve().parent / '../js/switch_tabs.js', 'r') as f:\n    switch_tabs_js = f.read()\nwith open(Path(__file__).resolve().parent / '../js/show_controls.js', 'r') as f:\n    show_controls_js = f.read()\nwith open(Path(__file__).resolve().parent / '../js/update_big_picture.js', 'r') as f:\n    update_big_picture_js = f.read()\n\nrefresh_symbol = '\ud83d\udd04'\ndelete_symbol = '\ud83d\uddd1\ufe0f'\nsave_symbol = '\ud83d\udcbe'\n\ntheme = gr.themes.Default(\n    font=['Noto Sans', 'Helvetica', 'ui-sans-serif', 'system-ui', 'sans-serif'],\n    font_mono=['IBM Plex Mono', 'ui-monospace', 'Consolas', 'monospace'],\n).set(\n    border_color_primary='#c5c5d2',\n    button_large_padding='6px 12px',\n    body_text_color_subdued='#484848',\n    background_fill_secondary='#eaeaea',\n    background_fill_primary='#fafafa',\n)\n\nif Path(\"notification.mp3\").exists():\n    audio_notification_js = \"document.querySelector('#audio_notification audio')?.play();\"\nelse:\n    audio_notification_js = \"\"\n\n\ndef list_model_elements():\n    elements = [\n        'loader',\n        'filter_by_loader',\n        'cpu_memory',\n        'auto_devices',\n        'disk',\n        'cpu',\n        'bf16',\n        'load_in_8bit',\n        'trust_remote_code',\n        'no_use_fast',\n        'use_flash_attention_2',\n        'load_in_4bit',\n        'compute_dtype',\n        'quant_type',\n        'use_double_quant',\n        'wbits',\n        'groupsize',\n        'model_type',\n        'pre_layer',\n        'triton',\n        'desc_act',\n        'no_inject_fused_attention',\n        'no_inject_fused_mlp',\n        'no_use_cuda_fp16',\n        'disable_exllama',\n        'disable_exllamav2',\n        'cfg_cache',\n        'no_flash_attn',\n        'num_experts_per_token',\n        'cache_8bit',\n        'cache_4bit',\n        'autosplit',\n        'threads',\n        'threads_batch',\n        'n_batch',\n        'no_mmap',\n        'mlock',\n        'no_mul_mat_q',\n        'n_gpu_layers',\n        'tensor_split',\n        'n_ctx',\n        'gpu_split',\n        'max_seq_len',\n        'compress_pos_emb',\n        'alpha_value',\n        'rope_freq_base',\n        'numa',\n        'logits_all',\n        'no_offload_kqv',\n        'row_split',\n        'tensorcores',\n        'streaming_llm',\n        'attention_sink_size',\n        'hqq_backend',\n    ]\n    if is_torch_xpu_available():\n        for i in range(torch.xpu.device_count()):\n            elements.append(f'gpu_memory_{i}')\n    else:\n        for i in range(torch.cuda.device_count()):\n            elements.append(f'gpu_memory_{i}')\n\n    return elements\n\n\ndef list_interface_input_elements():\n    elements = [\n        'max_new_tokens',\n        'auto_max_new_tokens',\n        'max_tokens_second',\n        'prompt_lookup_num_tokens',\n        'seed',\n        'temperature',\n        'temperature_last',\n        'dynamic_temperature',\n        'dynatemp_low',\n        'dynatemp_high',\n        'dynatemp_exponent',\n        'smoothing_factor',\n        'smoothing_curve',\n        'top_p',\n        'min_p',\n        'top_k',\n        'typical_p',\n        'epsilon_cutoff',\n        'eta_cutoff',\n        'repetition_penalty',\n        'presence_penalty',\n        'frequency_penalty',\n        'repetition_penalty_range',\n        'encoder_repetition_penalty',\n        'no_repeat_ngram_size',\n        'do_sample',\n        'penalty_alpha',\n        'mirostat_mode',\n        'mirostat_tau',\n        'mirostat_eta',\n        'grammar_string',\n        'negative_prompt',\n        'guidance_scale',\n        'add_bos_token',\n        'ban_eos_token',\n        'custom_token_bans',\n        'sampler_priority',\n        'truncation_length',\n        'custom_stopping_strings',\n        'skip_special_tokens',\n        'stream',\n        'tfs',\n        'top_a',\n    ]\n\n    # Chat elements\n    elements += [\n        'textbox',\n        'start_with',\n        'character_menu',\n        'history',\n        'name1',\n        'user_bio',\n        'name2',\n        'greeting',\n        'context',\n        'mode',\n        'custom_system_message',\n        'instruction_template_str',\n        'chat_template_str',\n        'chat_style',\n        'chat-instruct_command',\n    ]\n\n    # Notebook/default elements\n    elements += [\n        'textbox-notebook',\n        'textbox-default',\n        'output_textbox',\n        'prompt_menu-default',\n        'prompt_menu-notebook',\n    ]\n\n    # Model elements\n    elements += list_model_elements()\n\n    return elements\n\n\ndef gather_interface_values(*args):\n    output = {}\n    for i, element in enumerate(list_interface_input_elements()):\n        output[element] = args[i]\n\n    if not shared.args.multi_user:\n        shared.persistent_interface_state = output\n\n    return output\n\n\ndef apply_interface_values(state, use_persistent=False):\n    if use_persistent:\n        state = shared.persistent_interface_state\n\n    elements = list_interface_input_elements()\n    if len(state) == 0:\n        return [gr.update() for k in elements]  # Dummy, do nothing\n    else:\n        return [state[k] if k in state else gr.update() for k in elements]\n\n\ndef save_settings(state, preset, extensions_list, show_controls, theme_state):\n    output = copy.deepcopy(shared.settings)\n    exclude = ['name2', 'greeting', 'context', 'turn_template', 'truncation_length']\n    for k in state:\n        if k in shared.settings and k not in exclude:\n            output[k] = state[k]\n\n    output['preset'] = preset\n    output['prompt-default'] = state['prompt_menu-default']\n    output['prompt-notebook'] = state['prompt_menu-notebook']\n    output['character'] = state['character_menu']\n    output['default_extensions'] = extensions_list\n    output['seed'] = int(output['seed'])\n    output['show_controls'] = show_controls\n    output['dark_theme'] = True if theme_state == 'dark' else False\n\n    # Save extension values in the UI\n    for extension_name in extensions_list:\n        extension = getattr(extensions, extension_name, None)\n        if extension:\n            extension = extension.script\n            if hasattr(extension, 'params'):\n                params = getattr(extension, 'params')\n                for param in params:\n                    _id = f\"{extension_name}-{param}\"\n                    # Only save if different from default value\n                    if param not in shared.default_settings or params[param] != shared.default_settings[param]:\n                        output[_id] = params[param]\n\n    # Do not save unchanged settings\n    for key in list(output.keys()):\n        if key in shared.default_settings and output[key] == shared.default_settings[key]:\n            output.pop(key)\n\n    return yaml.dump(output, sort_keys=False, width=float(\"inf\"))\n\n\ndef create_refresh_button(refresh_component, refresh_method, refreshed_args, elem_class, interactive=True):\n    \"\"\"\n    Copied from https://github.com/AUTOMATIC1111/stable-diffusion-webui\n    \"\"\"\n    def refresh():\n        refresh_method()\n        args = refreshed_args() if callable(refreshed_args) else refreshed_args\n\n        return gr.update(**(args or {}))\n\n    refresh_button = gr.Button(refresh_symbol, elem_classes=elem_class, interactive=interactive)\n    refresh_button.click(\n        fn=lambda: {k: tuple(v) if type(k) is list else v for k, v in refresh().items()},\n        inputs=[],\n        outputs=[refresh_component]\n    )\n\n    return refresh_button\n", "path": "modules/ui.py"}]}