New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tensor indexing #3195
Tensor indexing #3195
Conversation
b2f5f28
to
5223763
Compare
CI MESSAGE: [2659393]: BUILD STARTED |
CI MESSAGE: [2659393]: BUILD FAILED |
CI MESSAGE: [2661776]: BUILD STARTED |
CI MESSAGE: [2661776]: BUILD PASSED |
} else if (IsValidType(tl_->type())) { | ||
tensors_[idx]->set_type(tl_->type()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This kept stale type in the views if the pointer or size didn't change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have Reset above, so it happened only with empty TV that got a type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It happend with something that had non-empty shape and type but 0 volume. And it was obviously a problem in TensorVector, since it had internally inconsistent type (TV had no_type and TLV had a proper type).
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
* Add layout handling * Add Python front-end for slicing Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
… set on views when pointer or size is not changed. Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
…istent args. Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
DALI_FAIL(make_string("The subscriptg for dimension ", i, | ||
" is specified both as an index and as a range.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DALI_FAIL(make_string("The subscriptg for dimension ", i, | |
" is specified both as an index and as a range.")); | |
DALI_FAIL(make_string("The subscriptg for dimension ", i, | |
" should not be specified both as an index and as a range.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
must not ;)
} | ||
if (step.IsDefined()) { | ||
DALI_FAIL(make_string("The subscriptg for dimension ", i, | ||
" is specified as an index - it cannot have a step.")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
" is specified as an index - it cannot have a step.")); | |
" should not be specified as an index and have have a step.")); |
|
||
|
||
if (s.IsDefined()) { | ||
num_subscripts = i + 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
num_subscripts = i + 1; | |
max_subscripts = i + 1; |
As it is not a number because some subscripts may be not defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mixed feelings here. It's used as the number (see subscripts_.resize(num_subscripts);
). I would gladly use input ndim here if I had it - but it's not available at construction.
void GetRanges(const workspace_t<Backend> &ws, const TensorListShape<> &in_shape) { | ||
int nsub = subscripts_.size(); | ||
int ndim = in_shape.sample_dim(); | ||
DALI_ENFORCE(ndim >= nsub, "Too many indices."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DALI_ENFORCE(ndim >= nsub, "Too many indices."); | |
DALI_ENFORCE(ndim >= nsub, make_string("Too many indices. Received: ", nsub, ", while input has only " ndim, " dimensions."); |
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
This pull request introduces 1 alert when merging 981923a into db01018 - view on LGTM.com new alerts:
|
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
CI MESSAGE: [2681926]: BUILD STARTED |
CI MESSAGE: [2681926]: BUILD FAILED |
@@ -1609,6 +1609,21 @@ def my_pipe(): | |||
|
|||
p = my_pipe(device_id=0, seed=1234, num_threads=3, set_affinity=True, py_num_workers=3) | |||
|
|||
def test_not_iterable(): | |||
import nvidia.dali._utils.hacks as hacks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why hacks? Workarounds?
assert np.array_equal(ref, cpu.at(i)) | ||
assert np.array_equal(ref, gpu.as_cpu().at(i)) | ||
|
||
def test_constant_ranges(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it repeats L56 and hides it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some copy paste... I'll take a look.
dali/python/nvidia/dali/data_node.py
Outdated
import nvidia.dali.fn | ||
if len(slice_args) == 0: | ||
if len(new_axes) == 0 or new_axes[-1] < len(idxs): | ||
print("Adding dim check for ", len(idxs)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need these prints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surely not. These are remnants from initial testing - I wanted to be 100% sure that the code follows the intended path and that the right checks fire when expected.
* Fix some tests. * Fix review issues. Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
CI MESSAGE: [2687330]: BUILD STARTED |
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
CI MESSAGE: [2687741]: BUILD STARTED |
CI MESSAGE: [2687330]: BUILD FAILED |
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
CI MESSAGE: [2687788]: BUILD STARTED |
CI MESSAGE: [2687788]: BUILD PASSED |
Signed-off-by: Michał Zientkiewicz mzient@gmail.com
Description
What happened in this PR
Added NumPy-like tensor indexing operator:
at
,lo
,hi
(and in the future alsostep
) arguments.__getitem__
toDataNode
which instantiates subscript operatordali.newaxis
anddali.newaxis(name)
Additional information
Affected modules and functionalities:
Key points relevant for the review:
Checklist
Tests
Documentation
DALI team only
Requirements
REQ IDs: SUBSCR.* except SUBSCR.06
JIRA TASK: 1617