Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The function
_convert_to_slice
was added recently, which causes indexing with elements to work (previously this didn't work). But when this change was made, it caused indexing with sequences to work.Type of change
The solution is to make
_convert_to_slice
only alter integer elements of the index.To further explain,
_convert_to_slice
will take an integer like1
and convert it into the sliceslice(1, 2)
. This is good because now the indexed tensorsA
andB
have the correct number of dimensions (i.e. they don't lose a dimension). But this isn't how we should treat things liket.tensor([0, 1, 2])
when they're used as an index, because they're already in the correct form for indexing (i.e. indexing with them won't delete a dimension).I've now added tests to
tests/unit/factored_matrix/test_get_item.py
which would have failed on both the version of TransformerLens before the recent change to FactoredMatrix, and the version after this change, but which now all pass.Screenshots
Checklist: