Commit b58789f
authored
Update trust_remote_code (#2256)
This pull request improves the handling of the `trust_remote_code` (or
`hf_remote`) option when loading models from Hugging Face repositories,
making the default behavior more secure and ensuring users must
explicitly opt in to executing remote code. It also updates
documentation and adds warnings to inform users about the security
implications.
**Security and behavior changes:**
* Changed the default for `hf_remote`/`trust_remote_code` to `False` in
both `builder.py` and `base.py`, so arbitrary code from Hugging Face
repositories is never executed unless the user explicitly enables it.
This matches the default behavior in the `transformers` library.
[[1]](diffhunk://#diff-11d14636083c4529597f09601b8f66e5df0094978debab425bfe6dd850cfcb50L199-R214)
[[2]](diffhunk://#diff-8a33668cd8981709ba426dab1b3d3145bd0756d1ebf1203657ba8b8aae860d45L89-R103)
* Added warnings in both `builder.py` and `base.py` to clearly notify
users when they have enabled `hf_remote`/`trust_remote_code` and explain
the associated security risks.
[[1]](diffhunk://#diff-11d14636083c4529597f09601b8f66e5df0094978debab425bfe6dd850cfcb50L199-R214)
[[2]](diffhunk://#diff-8a33668cd8981709ba426dab1b3d3145bd0756d1ebf1203657ba8b8aae860d45L89-R103)
**User interface and argument handling:**
* Added a `--trust_remote_code` command-line argument to
`awq-quantized-model.py`, and ensured this option is only forwarded to
model/tokenizer loading if the user has explicitly set it.
[[1]](diffhunk://#diff-a2b2e6bb32d7bd2dbfd980b04d4de97851bf0f12108a1be09a0c880cb68567efR49-R59)
[[2]](diffhunk://#diff-a2b2e6bb32d7bd2dbfd980b04d4de97851bf0f12108a1be09a0c880cb68567efL58-R71)
[[3]](diffhunk://#diff-a2b2e6bb32d7bd2dbfd980b04d4de97851bf0f12108a1be09a0c880cb68567efR153)
* Updated the help text for `hf_remote` in argument parsing to clarify
the new default and the security implications.
**Documentation updates:**
* Updated the documentation in `README.md` to accurately describe the
new default (`hf_remote=false`) and the risks of enabling remote code
execution.1 parent 7480c21 commit b58789f
4 files changed
Lines changed: 34 additions & 7 deletions
File tree
- examples/python
- src/python/py/models
- builders
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
49 | 60 | | |
50 | 61 | | |
51 | 62 | | |
| |||
55 | 66 | | |
56 | 67 | | |
57 | 68 | | |
58 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
59 | 72 | | |
60 | 73 | | |
61 | 74 | | |
| |||
137 | 150 | | |
138 | 151 | | |
139 | 152 | | |
| 153 | + | |
140 | 154 | | |
141 | 155 | | |
142 | 156 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
214 | | - | |
| 214 | + | |
215 | 215 | | |
216 | 216 | | |
217 | | - | |
| 217 | + | |
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
200 | 204 | | |
201 | 205 | | |
202 | 206 | | |
| |||
449 | 453 | | |
450 | 454 | | |
451 | 455 | | |
452 | | - | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
453 | 462 | | |
454 | 463 | | |
455 | 464 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
90 | 94 | | |
91 | 95 | | |
92 | 96 | | |
| |||
0 commit comments