Repository navigation
Commit abe9f62
committed
Stop overwriting external constants that a method returns
A model that returns one of its constants (a buffer or a parameter)
gives zeros at run time when it is exported with
external_constants=True. There is no error. The same model with its
constants kept inside the .pte file returns the right values.
MethodMeta decides whether an output is memory planned by looking for
an allocation or an inline data buffer. A constant stored in a .ptd
file has neither, so it looks like an output with no storage. The
Python bindings then give that output a new zero-filled buffer, and
set_output_data_ptr replaces the constant's data pointer with it. From
then on every read of the constant sees zeros, including operators that
use it to compute other outputs.
Treat a tensor whose data lives in an external file as memory planned,
the same way inline constants already are. One helper now computes this
for inputs, outputs and attributes, and the header documentation now
says that constants count as memory planned.
This changes 2 things that callers can see, for external constants
only. Inline constants already behaved this way:
- TensorInfo::is_memory_planned() now returns true for an output or an
attribute that is an external constant. The Python, Swift and
JavaScript bindings show this value.
- Method::set_output_data_ptr and Module::set_output on such an output
now return InvalidState, instead of silently replacing the constant's
data.
Add a Python test that returns a buffer from a program exported with
external constants, and a C++ test that checks the external constant
attributes of an existing test program report is_memory_planned().1 parent 2553a3a commit abe9f62
4 files changed
Lines changed: 52 additions & 12 deletions
File tree
- extension/pybindings/test
- runtime/executor
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3072 | 3072 | | |
3073 | 3073 | | |
3074 | 3074 | | |
| 3075 | + | |
| 3076 | + | |
| 3077 | + | |
| 3078 | + | |
| 3079 | + | |
| 3080 | + | |
| 3081 | + | |
| 3082 | + | |
| 3083 | + | |
| 3084 | + | |
| 3085 | + | |
| 3086 | + | |
| 3087 | + | |
| 3088 | + | |
| 3089 | + | |
| 3090 | + | |
| 3091 | + | |
| 3092 | + | |
3075 | 3093 | | |
3076 | 3094 | | |
3077 | 3095 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
38 | 49 | | |
39 | 50 | | |
40 | 51 | | |
| |||
308 | 319 | | |
309 | 320 | | |
310 | 321 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
| 322 | + | |
| 323 | + | |
315 | 324 | | |
316 | 325 | | |
317 | 326 | | |
| |||
366 | 375 | | |
367 | 376 | | |
368 | 377 | | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
| 378 | + | |
| 379 | + | |
373 | 380 | | |
374 | 381 | | |
375 | 382 | | |
| |||
415 | 422 | | |
416 | 423 | | |
417 | 424 | | |
418 | | - | |
419 | 425 | | |
420 | 426 | | |
421 | 427 | | |
| |||
424 | 430 | | |
425 | 431 | | |
426 | 432 | | |
427 | | - | |
428 | | - | |
| 433 | + | |
429 | 434 | | |
430 | 435 | | |
431 | 436 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
62 | 64 | | |
63 | 65 | | |
64 | 66 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
207 | 222 | | |
208 | 223 | | |
209 | 224 | | |
| |||
0 commit comments