Add better device idx parse checks#37376
Conversation
💊 CI failures summary and remediationsAs of commit 696a87c (more details on the Dr. CI page):
ci.pytorch.org: 1 failedThis comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker. This comment has been revised 64 times. |
f20a7d2 to
8aa8382
Compare
fa6365c to
12acd19
Compare
|
@zou3519 Maybe you could take a look when you have time? :) Thanks! |
There was a problem hiding this comment.
To make regex work, we would have to account for future/other device types (ROCM?, etc.). I wasn't sure how to do that properly... So I kept stoi.
There was a problem hiding this comment.
You could do something with regex groups, like the following so that we don't hardcode cpu & cuda:
#include <iostream>
#include <regex>
int main()
{
static const std::regex with_idx_regex("([a-zA-Z_]+):([0-9]+)");
static const std::regex without_idx_regex("([a-zA-Z_]+)");
std::smatch match;
const std::string device_string = "cuda:1";
const bool ok = std::regex_match(device_string, match, with_idx_regex);
if (ok) {
std::cout << "device: " << match[1].str() << std::endl;
std::cout << "idx: " << match[2].str() << std::endl;
}
}
The regex-based approach will probably have different error messages from the current parsing based approach, but it's a lot nicer than having to maintain our own parser for this
There was a problem hiding this comment.
Thanks! I'll take a look by eod tomorrow
779d023 to
abb6b71
Compare
zou3519
left a comment
There was a problem hiding this comment.
lgtm. Could you add an extra test for some two digit device numbers?
facebook-github-bot
left a comment
There was a problem hiding this comment.
@zou3519 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@zou3519 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@zou3519 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@zou3519 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
|
@ssnl do you mind if I rebase this? There seems to be an internal merge conflict |
|
Done!
…On Tue, May 12, 2020 at 13:27 Richard Zou ***@***.***> wrote:
@ssnl <https://github.com/SsnL> do you mind if I rebase this? There seems
to be an internal merge conflict
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#37376 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABLJMZPI3MUZ6XB2ON4A7V3RRGBI7ANCNFSM4MSJ43FA>
.
|
facebook-github-bot
left a comment
There was a problem hiding this comment.
@zou3519 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
| // To mimic `std::stoi` and to avoid including `Exception.h`, throw | ||
| // `std::invalid_argument`. | ||
| // We can't easily detect out-of-range, so we don't use `std::out_of_range`. | ||
| throw std::invalid_argument("Not an integer"); |
There was a problem hiding this comment.
I'm getting "error: no member named 'invalid_argument' in namespace 'std'
throw std::invalid_argument("Not an integer");" on some of the internal builds. As far as I can tell we don't need to throw nice errors here, so do you think it would be fine to remove these?
Alternatively we could try to include <stdexcept> but I'm not really sure what the downstream ramifications of that are
There was a problem hiding this comment.
Let's try including stdexcept! Without this check stoi(empty_string) would succeed.
facebook-github-bot
left a comment
There was a problem hiding this comment.
@zou3519 has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: Fixes pytorch#32079 Pull Request resolved: pytorch#37376 Differential Revision: D21476036 Pulled By: zou3519 fbshipit-source-id: 86907083c23cbaf165b645307fb340f2656b814e
Fixes #32079