Skip to content

Commit b5a6904

Browse files
committed
Make --trust-remote-code immutable from the UI/API
1 parent efaf2ae commit b5a6904

5 files changed

Lines changed: 11 additions & 9 deletions

File tree

modules/loaders.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,13 @@
4545
'disk',
4646
'use_double_quant',
4747
'bf16',
48-
'trust_remote_code',
4948
'no_use_fast',
5049
],
5150
'ExLlamav3_HF': [
5251
'ctx_size',
5352
'cache_type',
5453
'gpu_split',
5554
'cfg_cache',
56-
'trust_remote_code',
5755
'no_use_fast',
5856
'enable_tp',
5957
'tp_backend',
@@ -82,7 +80,6 @@
8280
'no_xformers',
8381
'no_sdpa',
8482
'cfg_cache',
85-
'trust_remote_code',
8683
'no_use_fast',
8784
],
8885
'ExLlamav2': [

modules/shared.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174

175175

176176
args = parser.parse_args()
177+
original_args = copy.deepcopy(args)
177178
args_defaults = parser.parse_args([])
178179

179180
# Create a mapping of all argument aliases to their canonical names
@@ -295,7 +296,13 @@
295296
def do_cmd_flags_warnings():
296297
# Security warnings
297298
if args.trust_remote_code:
298-
logger.warning('trust_remote_code is enabled. This is dangerous.')
299+
logger.warning(
300+
"The `--trust-remote-code` flag is enabled.\n"
301+
"This allows models to execute arbitrary code on your machine.\n\n"
302+
"1. Only use with models from sources you fully trust.\n"
303+
"2. Set an access password with `--gradio-auth`."
304+
)
305+
299306
if 'COLAB_GPU' not in os.environ and not args.nowebui:
300307
if args.share:
301308
logger.warning("The gradio \"share link\" feature uses a proprietary executable to create a reverse tunnel. Use it with care.")

modules/transformers_loader.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def load_tokenizer(model_name, tokenizer_dir=None):
123123

124124
tokenizer = AutoTokenizer.from_pretrained(
125125
path_to_model,
126-
trust_remote_code=shared.args.trust_remote_code,
126+
trust_remote_code=shared.original_args.trust_remote_code,
127127
use_fast=not shared.args.no_use_fast
128128
)
129129

@@ -140,13 +140,13 @@ def load_model_HF(model_name):
140140
'torch_dtype': torch.bfloat16 if shared.args.bf16 else torch.float16,
141141
}
142142

143-
if shared.args.trust_remote_code:
143+
if shared.original_args.trust_remote_code:
144144
params['trust_remote_code'] = True
145145

146146
if shared.args.force_safetensors:
147147
params['force_safetensors'] = True
148148

149-
config = AutoConfig.from_pretrained(path_to_model, trust_remote_code=shared.args.trust_remote_code)
149+
config = AutoConfig.from_pretrained(path_to_model, trust_remote_code=shared.original_args.trust_remote_code)
150150

151151
if 'chatglm' in model_name.lower():
152152
LoaderClass = AutoModel

modules/ui.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ def list_model_elements():
160160
'no_sdpa',
161161
'cfg_cache',
162162
'cpp_runner',
163-
'trust_remote_code',
164163
'no_use_fast',
165164
'model_draft',
166165
'draft_max',

modules/ui_model_menu.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ def create_ui():
5757
shared.gradio['autosplit'] = gr.Checkbox(label="autosplit", value=shared.args.autosplit, info='Automatically split the model tensors across the available GPUs.')
5858
shared.gradio['enable_tp'] = gr.Checkbox(label="enable_tp", value=shared.args.enable_tp, info='Enable tensor parallelism (TP).')
5959
shared.gradio['cpp_runner'] = gr.Checkbox(label="cpp-runner", value=shared.args.cpp_runner, info='Enable inference with ModelRunnerCpp, which is faster than the default ModelRunner.')
60-
shared.gradio['trust_remote_code'] = gr.Checkbox(label="trust-remote-code", value=shared.args.trust_remote_code, info='Set trust_remote_code=True while loading the tokenizer/model. To enable this option, start the web UI with the --trust-remote-code flag.', interactive=shared.args.trust_remote_code)
6160
shared.gradio['tensorrt_llm_info'] = gr.Markdown('* TensorRT-LLM has to be installed manually in a separate Python 3.10 environment at the moment. For a guide, consult the description of [this PR](https://github.com/oobabooga/text-generation-webui/pull/5715). \n\n* `ctx_size` is only used when `cpp-runner` is checked.\n\n* `cpp_runner` does not support streaming at the moment.')
6261

6362
# Multimodal

0 commit comments

Comments
 (0)