-
Notifications
You must be signed in to change notification settings - Fork 25
[WIP] BytePS strategy #31
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
Open
sangkeun00
wants to merge
5
commits into
petuum:master
Choose a base branch
from
sangkeun00:byteps_sangkeun
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b61db35
BytePS init
sangkeun00 055f3ac
fixed pylint errors
sangkeun00 14acc2f
Merge branch 'master' of https://github.com/petuum/autodist into byte…
sangkeun00 1978865
add multinomial byteps
sangkeun00 3b3196a
fixed strategy/__init__.py
sangkeun00 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| """BytePS StrategyBuilder(s).""" | ||
| from autodist.strategy.base import Strategy, StrategyBuilder | ||
| from autodist.proto import strategy_pb2 | ||
| from autodist.strategy.ps_lb_strategy import PSLoadBalancing, byte_size_load_fn | ||
|
|
||
|
|
||
| class BytePS(PSLoadBalancing): | ||
| """ | ||
| Generates the BytePS Strategy from https://github.com/bytedance/byteps. | ||
|
|
||
| The BytePS strategy exploits CPU-only nodes for communication while GPU nodes | ||
| for computatoin. | ||
| """ | ||
|
|
||
| def __init__(self, local_proxy_variable=False, sync=True, staleness=0): | ||
| PSLoadBalancing.__init__(self, local_proxy_variable, sync, staleness) | ||
|
|
||
| # pylint: disable=attribute-defined-outside-init | ||
| def build(self, graph_item, resource_spec): | ||
| """Generate the strategy.""" | ||
| expr = Strategy() | ||
|
|
||
| # get each variable, generate variable synchronizer config | ||
| expr.graph_config.replicas.extend([k for k, v in resource_spec.gpu_devices]) | ||
|
|
||
| # find all variables | ||
| variables = graph_item.get_trainable_variables() | ||
| reduction_device_names = [k for k, _ in resource_spec.cpu_only_devices] | ||
| self.loads = {ps: 0.0 for ps in reduction_device_names} | ||
|
|
||
| # Mark each variable to be synchronized with a Parameter Server | ||
| node_config = [self._gen_ps_node_config(var, self._local_proxy_variable, self._sync, self._staleness) | ||
| for var in variables] | ||
| expr.node_config.extend(node_config) | ||
|
|
||
| return expr | ||
|
|
||
|
|
||
| class MultinomialBytePS(StrategyBuilder): | ||
| """ | ||
| BytePS with Multinomial Load Balancing. | ||
|
|
||
| Each PS gets assigned variables of which size is proportional to | ||
| its bandwidth. | ||
| """ | ||
|
|
||
| def __init__(self, local_proxy_variable=False, sync=True, staleness=0): | ||
| self._local_proxy_variable = local_proxy_variable | ||
| self._sync = sync | ||
| self._staleness = staleness | ||
| if self._staleness > 0: | ||
| assert self._sync, 'If staleness is positive, sync has to be set true' | ||
| self.loads = {} | ||
| self.bandwidth = {} | ||
| super().__init__() | ||
|
|
||
| def build(self, graph_item, resource_spec): | ||
| """Generate the Strategy.""" | ||
| expr = Strategy() | ||
|
|
||
| # get each variable, generate variable synchronizer config | ||
| expr.graph_config.replicas.extend([k for k, v in resource_spec.gpu_devices]) | ||
| for k, v in resource_spec.node_cpu_devices.items(): | ||
| if k not in resource_spec.node_gpu_devices: | ||
| expr.graph_config.replicas.extend(v) | ||
|
|
||
| # find all variables | ||
| variables = graph_item.get_trainable_variables() | ||
| reduction_device_names = [k for k, _ in resource_spec.cpu_devices] | ||
| bandwidth = resource_spec.network_bandwidth | ||
| self.bandwidth = {ps: bandwidth[ps.split(':')[0]] for ps in reduction_device_names} | ||
| self.loads = {ps: 1e-8 / self.bandwidth[ps] for ps in reduction_device_names} | ||
|
|
||
| # Mark each variable to be synchronized with a Parameter Server | ||
| node_config = [self._gen_ps_node_config(var, self._local_proxy_variable, self._sync, self._staleness) | ||
| for var in variables] | ||
| expr.node_config.extend(node_config) | ||
|
|
||
| return expr | ||
|
|
||
| def _gen_ps_node_config(self, var, local_proxy_variable, sync, staleness): | ||
| """ | ||
| Creates a NodeConfig specifying synchronization with Parameter Servers. | ||
|
|
||
| Args: | ||
| var (Variable): The variable to generate a config for. | ||
|
|
||
| Returns: | ||
| strategy_pb2.Strategy.Node: the config for the node. | ||
| """ | ||
| min_ps = min(self.loads, key=self.loads.get) | ||
| self.loads[min_ps] += byte_size_load_fn(var) / self.bandwidth[min_ps] | ||
|
|
||
| node = strategy_pb2.Strategy.Node() | ||
| node.var_name = var.name | ||
| node.PSSynchronizer.reduction_destination = min_ps | ||
| node.PSSynchronizer.local_replication = local_proxy_variable | ||
| node.PSSynchronizer.sync = sync | ||
| node.PSSynchronizer.staleness = staleness | ||
| return node | ||
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.
Uh oh!
There was an error while loading. Please reload this page.