Repository navigation
Commit 73602df
authored
Fix gather on sliced nullable string and list tensors (#1289)
> # Summary
>
> Fix wrong values when gathering or materializing nullable
`StringTensor`/`VarLenTensor` built from a sliced Arrow array or cuDF
series.
>
> ```python
> import pyarrow as pa, torch
> from sdm import StringTensor
>
> s = StringTensor.from_arrow(pa.array(["LONGPREFIX", "a", None,
"b"]).slice(1))
> s.tolist() # ['a', None, 'b']
> s[torch.tensor([0, 2])].tolist() # main: ['LONGPREFIX', '']; expected:
['a', 'b']
> ```
>
> # Description of the change
>
> Root cause: for nullable inputs, `StringTensor.from_arrow`,
`StringTensor.from_cudf` and `VarLenTensor.from_arrow` slice the
offsets, so `_offset` is a view with its own nonzero storage offset.
`_materialize`, `_layout_view` and `_valid` pass only the wrapper's
storage offset to `torch.as_strided`, which addresses the underlying
storage absolutely, so they read offsets (and validity) from before the
slice.
>
> Fix: add the inner tensor's storage offset in those `as_strided` calls
and subtract it again in `_from_layout_view`. This keeps inner buffers
zero-copy and adds no branches, so it stays compile-friendly.
Normalizing inner tensors in the constructor (cloning views) was the
alternative; it copies buffers and adds a data-dependent branch for
symbolic storage offsets.
>
> # Validation
>
> - New regression tests for sliced nullable Arrow input (`string`,
`large_string`, list) on CPU and sliced nullable cuDF input on CUDA; the
CPU tests fail on `main`.
> - CPU: `test/tensor` (166 passed), `test/processing test/relational
test/nn` (580 passed).
> - GPU (torch 2.14.1+cu130, cuDF): `test/tensor` (219 passed),
`test/processing test/relational test/nn` (826 passed), cuDF repro above
returns `['a', 'b']`.1 parent b780fc9 commit 73602df
3 files changed
Lines changed: 63 additions & 18 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1009 | 1009 | | |
1010 | 1010 | | |
1011 | 1011 | | |
| 1012 | + | |
| 1013 | + | |
1012 | 1014 | | |
1013 | 1015 | | |
1014 | 1016 | | |
1015 | 1017 | | |
1016 | | - | |
| 1018 | + | |
1017 | 1019 | | |
1018 | 1020 | | |
1019 | 1021 | | |
| |||
1440 | 1442 | | |
1441 | 1443 | | |
1442 | 1444 | | |
| 1445 | + | |
| 1446 | + | |
1443 | 1447 | | |
1444 | 1448 | | |
1445 | 1449 | | |
1446 | 1450 | | |
1447 | | - | |
| 1451 | + | |
1448 | 1452 | | |
1449 | 1453 | | |
1450 | 1454 | | |
1451 | 1455 | | |
| 1456 | + | |
1452 | 1457 | | |
1453 | 1458 | | |
1454 | 1459 | | |
1455 | 1460 | | |
1456 | 1461 | | |
1457 | 1462 | | |
1458 | | - | |
| 1463 | + | |
1459 | 1464 | | |
1460 | 1465 | | |
1461 | 1466 | | |
| |||
1494 | 1499 | | |
1495 | 1500 | | |
1496 | 1501 | | |
1497 | | - | |
1498 | | - | |
1499 | | - | |
1500 | | - | |
1501 | | - | |
1502 | | - | |
| 1502 | + | |
1503 | 1503 | | |
1504 | 1504 | | |
1505 | 1505 | | |
| |||
1508 | 1508 | | |
1509 | 1509 | | |
1510 | 1510 | | |
1511 | | - | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
1512 | 1514 | | |
1513 | 1515 | | |
1514 | 1516 | | |
| |||
1529 | 1531 | | |
1530 | 1532 | | |
1531 | 1533 | | |
1532 | | - | |
1533 | | - | |
1534 | | - | |
1535 | | - | |
1536 | | - | |
1537 | | - | |
1538 | | - | |
1539 | | - | |
| 1534 | + | |
| 1535 | + | |
1540 | 1536 | | |
1541 | 1537 | | |
1542 | 1538 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
116 | 129 | | |
117 | 130 | | |
118 | 131 | | |
| |||
148 | 161 | | |
149 | 162 | | |
150 | 163 | | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
151 | 175 | | |
152 | 176 | | |
153 | 177 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
216 | 216 | | |
217 | 217 | | |
218 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
219 | 244 | | |
220 | 245 | | |
221 | 246 | | |
| |||
0 commit comments