Skip to content
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

Add kwargs to idist.barrier #2310

Closed
wants to merge 23 commits into from
Closed

Conversation

fco-dv
Copy link
Contributor

@fco-dv fco-dv commented Nov 4, 2021

Fixes #2213

Description:

Add kwargs to idist.barrier for native , xla and horovod backends. Need to add relevant example code.

Check list:

  • New tests are added (if a new feature is added)
  • New doc strings: description and/or example code are in RST format
  • Documentation is updated (if required)

@github-actions github-actions bot added the module: distributed Distributed module label Nov 4, 2021
Copy link
Contributor

@KickItLikeShika KickItLikeShika left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @fco-dv! Just left a single comment

def _check_barrier_fn_kwargs(self, barrier_fn: Callable, kwargs_dict: Dict[str, Any]) -> Dict[str, Any]:
bnd_keys = set()
for param in signature(barrier_fn).parameters.values():
if param.kind == param.POSITIONAL_OR_KEYWORD:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we simplify this a bit? I think we can do this inside the loop, for example in the else we delete the key directly maybe? and make a bool flag maybe and raise the warning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comment, @KickItLikeShika , I will try to simplify this

@vfdev-5 vfdev-5 requested a review from sdesrozis November 5, 2021 11:51
if param.kind == param.POSITIONAL_OR_KEYWORD:
bnd_keys.add(param.name)
extra_keys = sorted(list(set(kwargs_dict) - bnd_keys))
fn_params_name = set(
Copy link
Contributor

@sdesrozis sdesrozis Nov 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m wondering whether comprehension list would be more simple.

I think the method bind of the class Signature could help.

def barrier(self) -> None:
def barrier(self, **kwargs: Any) -> None:
kwargs = self._check_barrier_fn_kwargs(barrier_fn=hvd.allreduce, kwargs_dict=kwargs)
if "tensor" in kwargs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why redefining these arguments and not simply avoid it ? IMO it’s confusing.

# https://github.com/horovod/horovod/issues/159#issuecomment-424834603
# hvd.allreduce(torch.tensor(0, device=self.device()), name="barrier")
hvd.allreduce(torch.tensor(0, device="cpu"), name="barrier")
hvd.allreduce(tensor=torch.tensor(0, device="cpu"), name="barrier", **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that a barrier function was recently introduced. We could use it in a next PR (and handle older version).

xm.rendezvous("barrier")
def barrier(self, **kwargs: Any) -> None:
kwargs = self._check_barrier_fn_kwargs(barrier_fn=xm.rendezvous, kwargs_dict=kwargs)
if "tag" in kwargs:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same remark than above


- | "horovod" : ``average`` (default, None), ``compression`` (default, Compression.none),
| ``op`` (default, None), ``prescale_factor`` (default, 1.0), ``postscale_factor`` (default, 1.0),
| ``process_set`` (default, global_process_set).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redefinition is confusing IMO

@@ -275,8 +277,24 @@ def _do_all_gather(self, tensor: torch.Tensor) -> torch.Tensor:
def _do_broadcast(self, tensor: torch.Tensor, src: int) -> torch.Tensor:
pass

def _check_barrier_fn_kwargs(self, barrier_fn: Callable, kwargs_dict: Dict[str, Any]) -> Dict[str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is more general than its name suggests. You did a signature checker. It could be called check_method_args and note that type could be also checked.

@sdesrozis
Copy link
Contributor

Hey @fco-dv I left a few comments.

DevPranjal and others added 11 commits November 23, 2021 23:11
* Add doctests for RMSE and MeanPairwiseDistance

* Add doctests for RMSE and MeanPairwiseDistance

* Make metric name consistent
…actionalAbsoluteError``, ``CanberraMetric``, ``GeometricMeanAbsoluteError``) (pytorch#2323)

* added doctest for contrib regression metrics

* removed Engine definition and variable name changes

* added import of contrib.regression

Co-authored-by: Sylvain Desroziers <[email protected]>
* pytorch#2313 fix bug in StateParamScheduler attach method

* pytorch#2313 add assert if KeyError is raised

* pytorch#2313 update test_multiple_scheduler_with_save_history

Co-authored-by: vfdev <[email protected]>
fco-dv and others added 2 commits November 23, 2021 23:11
* pytorch#2090 make work EMAHandler with StateParamScheduler

* pytorch#2295 update docstring for parameter `create_new`

* pytorch#2295 fixing attach method logic and update associated tests

* pytorch#2295 fix unused import / remove useless test

* pytorch#2295 fix tests

* pytorch#2295 rm else statement

* Update ignite/handlers/state_param_scheduler.py

Co-authored-by: vfdev <[email protected]>

* Update ignite/handlers/state_param_scheduler.py

Co-authored-by: vfdev <[email protected]>

* pytorch#2295 update tests assert messages

* pytorch#2295 update tests, add working example with EMAHandler

Co-authored-by: vfdev <[email protected]>
@fco-dv fco-dv marked this pull request as draft November 23, 2021 22:12
@fco-dv fco-dv closed this Nov 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: distributed Distributed module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FR] Add kwargs to idist.barrier
6 participants