-
Notifications
You must be signed in to change notification settings - Fork 187
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
Fix device handling and logits concatenation in OliveEvaluator #1615
base: main
Are you sure you want to change the base?
Conversation
- Add exception handling for unsupported devices in `device_string_to_torch_device` method. - Correct logits concatenation in `OnnxEvaluator` by using `logits_dict` instead of `logits`. - Initialize `logits_dict` in `PyTorchEvaluator` to handle different result types. - Update `_inference` method in `PyTorchEvaluator` to handle different result types and concatenate logits correctly.
306da8e
to
09138a8
Compare
@@ -196,7 +196,11 @@ def compute_throughput(metric: Metric, latencies: Any) -> MetricResult: | |||
class _OliveEvaluator(OliveEvaluator): | |||
@staticmethod | |||
def device_string_to_torch_device(device: Device): | |||
return torch.device("cuda") if device == Device.GPU else torch.device(device) | |||
try: |
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.
maybe we can just do torch.device("cuda") if device == Device.GPU else torch.device("cpu")
. Otherwise, this would raise the warning for npu targets everytime. since this method is only used when evaluating pytorch models, I think it's save to just return cuda or cpu only.
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.
So we will only consider cuda
and cpu
, for now at least? Are we planning to support device like Apple mps
?
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.
yes, there are no plans for other torch devices like mps for now.
if isinstance(result, torch.Tensor): | ||
logits.append(result.cpu()) | ||
elif isinstance(result, (list, tuple)): | ||
logits.append([r.cpu() for r in result]) | ||
elif isinstance(result, dict): | ||
for k in result: | ||
logits_dict[k].append(result[k].cpu()) |
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.
How can we handle the case when result has logits attribute?
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.
You mean result like { "logits": tensor }
?
device_string_to_torch_device
method.OnnxEvaluator
by usinglogits_dict
instead oflogits
.logits_dict
inPyTorchEvaluator
to handle different result types._inference
method inPyTorchEvaluator
to handle different result types and concatenate logits correctly.Describe your changes
Checklist before requesting a review
lintrunner -a
(Optional) Issue link