-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Make keying of examples explicit. #21777
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a4d253e
Make keying of examples explicit.
robertwb 31c7788
mypy
robertwb 753427f
Merge branch 'master' into ml-keys
robertwb 7e01380
fix merge, yapf
robertwb dcd3289
MaybeKeyed
robertwb 656919a
Merge branch 'master' into ml-keys
robertwb d694586
More List -> Sequence changes.
robertwb 02bfe39
one more instance of keyed
robertwb 1dc8dcc
Properly type unions.
robertwb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ | |
from typing import Callable | ||
from typing import Dict | ||
from typing import Iterable | ||
from typing import List | ||
from typing import Sequence | ||
from typing import Union | ||
|
||
import torch | ||
|
@@ -87,7 +87,7 @@ def _convert_to_device(self, examples: torch.Tensor) -> torch.Tensor: | |
|
||
def run_inference( | ||
self, | ||
batch: List[Union[torch.Tensor, Dict[str, torch.Tensor]]], | ||
batch: Sequence[Union[torch.Tensor, Dict[str, torch.Tensor]]], | ||
model: torch.nn.Module, | ||
**kwargs) -> Iterable[PredictionResult]: | ||
""" | ||
|
@@ -119,7 +119,7 @@ def run_inference( | |
predictions = model(batched_tensors, **prediction_params) | ||
return [PredictionResult(x, y) for x, y in zip(batch, predictions)] | ||
|
||
def get_num_bytes(self, batch: List[torch.Tensor]) -> int: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do the same There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
def get_num_bytes(self, batch: Sequence[torch.Tensor]) -> int: | ||
"""Returns the number of bytes of data for a batch of Tensors.""" | ||
# If elements in `batch` are provided as a dictionaries from key to Tensors | ||
if isinstance(batch[0], dict): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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 wonder if there's any way to make this more readable or simple. All these nested lists are making my eyes a little buggy.
Can we perhaps use constants here?
BASIC_MODEL_HANDLER = ModelHandler[Tuple[KeyT, ExampleT]
KEYED_PREDICTION = Tuple[KeyT, PredictionT]
Or are there any other ways to make some of this templating go away?
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 played around with this a bit, don't see a way to really make things much simpler. It is possible delete the generic, but then it becomes harder to reason about the order of the nested arguments.