Repository navigation
Fix call to fork_rng by by specifying device type - #180512
frost-intel wants to merge 8 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180512
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (2 Unrelated Failures)As of commit f10754f with merge base f97c056 ( BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
guangyey
left a comment
There was a problem hiding this comment.
Could you please help me understand what will happen if without this fix.
| devices = list(devices) | ||
| if devices: | ||
| try: | ||
| device_type = torch.device(devices[0]).type |
There was a problem hiding this comment.
We could move this to line 203/218 such as:
if devices is None:
num_devices = device_mod.device_count()
devices = list(range(num_devices))
if num_devices > 1 and not _fork_rng_warned_already:
device_type = devices[0].type
message = (
f"{device_type.upper()} reports that you have {num_devices} available devices, and "
f"you have used {_caller} without explicitly specifying which devices are being used. "
f"For safety, we initialize *every* {device_type.upper()} device by default, which can "
f"be quite slow if you have a lot of {device_type.upper()}s. If you know that you are only"
f" making use of a few {device_type.upper()} devices, set the environment variable "
f"{device_type.upper()}_VISIBLE_DEVICES or the '{_devices_kw}' keyword argument of {_caller} "
"with the set of devices you are actually using. For example, if you are using CPU only, "
"set device.upper()_VISIBLE_DEVICES= or devices=[]; if you are using device 0 only, "
f"set {device_type.upper()}_VISIBLE_DEVICES=0 or devices=[0]. To initialize all devices "
f"and suppress this warning, set the '{_devices_kw}' keyword argument to "
f"`range(torch.{device_type}.device_count())`."
)
warnings.warn(message, stacklevel=2)
_fork_rng_warned_already = True
There was a problem hiding this comment.
This doesn't solve any problems because device_mod is set by device_type on line 186/201.
There was a problem hiding this comment.
You are right! I think we could use torch.get_device_module to avoid these if statements.
| } | ||
| ) | ||
| with torch.random.fork_rng(devices=devices): | ||
| device_type = stages[0].device if stages else "cuda" |
There was a problem hiding this comment.
| device_type = stages[0].device if stages else "cuda" | |
| device_type = devices[0].type if devices else None |
stages[0] may be a cpu.
There was a problem hiding this comment.
stages will not contain cpu based on the logic immediately above but I have no objection to changing this to None.
There was a problem hiding this comment.
I notice stages is filtered by cpu in line 423. Doesn't it mean it may contain cpu.
@guangyey The call in Technically, the fix for the specific error we are seeing could be fixed in either |
There was a problem hiding this comment.
| device_mod = torch.get_device_module(device_type) |
| if devices is None: | ||
| num_devices = device_mod.device_count() | ||
| if num_devices > 1 and not _fork_rng_warned_already: | ||
| message = ( |
There was a problem hiding this comment.
device_type = device_type or torch.accelerator.current_accelerator().type
There was a problem hiding this comment.
num_devices > 1 already means that current accelerator is available.
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
7e12b38 to
3fc101a
Compare
guangyey
left a comment
There was a problem hiding this comment.
Thanks for your update!
| } | ||
| ) | ||
| with torch.random.fork_rng(devices=devices): | ||
| device_type = devices[0] if devices else None |
There was a problem hiding this comment.
I'm confused by this?
How was this code working before?
There was a problem hiding this comment.
This code was erroneously added recently in #177728. Other existing calls to fork_rng specify device_type, which this new call didn't do.
There was a problem hiding this comment.
Thanks for the pointer!
And the fix!
|
Hi @janeyx99 could you please help take a look when you have a chance? Alban seems to be OOO. |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
d3cfa63 to
def7d3b
Compare
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: 1 mandatory check(s) failed. The first few are: Dig deeper by viewing the failures on hud |
|
@pytorchbot merge -i |
|
|
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
Co-authored-by: Yu, Guangye <[email protected]>
|
Successfully rebased |
4b0a838 to
f10754f
Compare
|
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Fixes a bug for non-CUDA devices introduced by pytorch#177728 due to a misused call to fork_rng * Since the call to fork_rng should specify the device type, I specify this in `schedules.py` * The design of fork_rng seems outdated since the adoption of non-CUDA devices. I change the signature so the device_type default argument is `None`, and is inferred from the passed devices. If it can't be inferred from the device list (because it's a list of ints, for example) we still fallback to the previous value of "cuda". Pull Request resolved: pytorch#180512 Approved by: https://github.com/guangyey, https://github.com/albanD Co-authored-by: Yu, Guangye <[email protected]>
Fixes a bug for non-CUDA devices introduced by pytorch#177728 due to a misused call to fork_rng * Since the call to fork_rng should specify the device type, I specify this in `schedules.py` * The design of fork_rng seems outdated since the adoption of non-CUDA devices. I change the signature so the device_type default argument is `None`, and is inferred from the passed devices. If it can't be inferred from the device list (because it's a list of ints, for example) we still fallback to the previous value of "cuda". Pull Request resolved: pytorch#180512 Approved by: https://github.com/guangyey, https://github.com/albanD Co-authored-by: Yu, Guangye <[email protected]>
Fixes a bug for non-CUDA devices introduced by #177728 due to a misused call to fork_rng
schedules.pyNone, and is inferred from the passed devices. If it can't be inferred from the device list (because it's a list of ints, for example) we still fallback to the previous value of "cuda".