Commit b3a4ec8
committed
Add :safetensors_reader option to load_model/2
Allows callers to override the function used to read `.safetensors`
parameter files. The override receives a file path and must return a
map from tensor name to an `Nx.Tensor` or `Nx.LazyContainer`. Defaults
to the existing `&Safetensors.read!(&1, lazy: true)`, so behaviour is
unchanged when the option is not supplied.
This is a small seam for custom readers — for example, a memory-mapped
loader backed by a resource binary, which can keep peak memory bounded
to a single tensor when loading very large checkpoints.1 parent 851632d commit b3a4ec8
2 files changed
Lines changed: 39 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
568 | 568 | | |
569 | 569 | | |
570 | 570 | | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
571 | 578 | | |
572 | 579 | | |
573 | 580 | | |
| |||
617 | 624 | | |
618 | 625 | | |
619 | 626 | | |
| 627 | + | |
620 | 628 | | |
621 | 629 | | |
622 | 630 | | |
| |||
659 | 667 | | |
660 | 668 | | |
661 | 669 | | |
662 | | - | |
| 670 | + | |
663 | 671 | | |
664 | 672 | | |
665 | 673 | | |
| |||
768 | 776 | | |
769 | 777 | | |
770 | 778 | | |
771 | | - | |
772 | | - | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
773 | 784 | | |
774 | 785 | | |
775 | 786 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
87 | 112 | | |
88 | 113 | | |
0 commit comments