-
Notifications
You must be signed in to change notification settings - Fork 656
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 bug of Multi-Client src tick output order #6221
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
96c5a18
Fix bug of Multi-Client src tick output order
chengtbf a96a643
Merge branch 'master' into dev_cc_fix_src_output_order
chengtbf 54e2d01
Merge branch 'master' into dev_cc_fix_src_output_order
chengtbf 464ccef
Merge branch 'master' into dev_cc_fix_src_output_order
chengtbf 4f62da6
Add input/output ctrl edge to DstSubTick for order io and callback_no…
chengtbf c008b3b
add test scripts
chengtbf 32aa2c3
remove note
chengtbf 8e9edd9
auto format by CI
oneflow-ci-bot daecbbf
add note of sleep
chengtbf b063a04
auto format by CI
oneflow-ci-bot File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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 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 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 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 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,117 @@ | ||
""" | ||
Copyright 2020 The OneFlow Authors. All rights reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
""" | ||
import os | ||
import time | ||
import unittest | ||
import numpy as np | ||
|
||
import oneflow as flow | ||
import oneflow.unittest | ||
|
||
|
||
def _test_graph_pipeline_delay_output(test_case): | ||
class StageLayerModule(flow.nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
self.linear1 = flow.nn.Linear(10, 8, False) | ||
self.linear2 = flow.nn.Linear(8, 10) | ||
flow.nn.init.constant_(self.linear1.weight, 0.023) | ||
flow.nn.init.constant_(self.linear2.weight, 1.23) | ||
|
||
def forward(self, x): | ||
out0 = self.linear1(x) | ||
out0 = out0 + 1.0 | ||
out0 = out0 * 2.0 | ||
out1 = self.linear2(out0) | ||
return out1 | ||
|
||
P0 = flow.placement("cuda", {0: [0]}) | ||
P1 = flow.placement("cuda", {0: [1]}) | ||
B = flow.sbp.broadcast | ||
|
||
class PipelineModule(flow.nn.Module): | ||
def __init__(self): | ||
super().__init__() | ||
self.layer_0 = StageLayerModule() | ||
self.layer_1 = StageLayerModule() | ||
self.layer_0.to_consistent(P0, B) | ||
self.layer_1.to_consistent(P1, B) | ||
|
||
def forward(self, x): | ||
# stage 0 | ||
in0 = x.to_consistent(P0, B) | ||
out0 = self.layer_0(in0) | ||
# stage 1 | ||
in1 = out0.to_consistent(P1, B) | ||
out1 = self.layer_1(in1) | ||
return out1 | ||
|
||
pp_m = PipelineModule() | ||
pp_m.train() | ||
of_sgd = flow.optim.SGD(pp_m.parameters(), lr=0.001) | ||
|
||
class PipelineGraph(flow.nn.Graph): | ||
def __init__(self): | ||
super().__init__() | ||
self.pp_m = pp_m | ||
self.pp_m.layer_0.config.stage_id = 0 | ||
self.pp_m.layer_1.config.stage_id = 1 | ||
self.config.set_gradient_accumulation_steps(4) | ||
self.add_optimizer(of_sgd) | ||
|
||
def build(self, x, y): | ||
pp_out = self.pp_m(x) | ||
loss = pp_out.mean() | ||
loss.backward() | ||
y = x + y | ||
free_out = y.to_consistent(P1, B) | ||
return loss, free_out | ||
|
||
pp_g = PipelineGraph() | ||
rank = flow.env.get_rank() | ||
for i in range(3): | ||
x = flow.randn(16, 10) | ||
y = flow.randn(16, 10) | ||
x = x.to_consistent(P0, B) | ||
y = y.to_consistent(P0, B) | ||
if rank == 1: | ||
time.sleep(2) | ||
loss_pack_4, free_out = pp_g(x, y) | ||
if rank == 1: | ||
time.sleep(2) | ||
chengtbf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print( | ||
"rank: ", | ||
rank, | ||
"packed loss with 4 micro-batch = ", | ||
loss_pack_4.to_local(), | ||
) | ||
print( | ||
"rank: ", | ||
rank, | ||
"packed image with 4 micro-batch = ", | ||
free_out.to_local(), | ||
) | ||
|
||
|
||
@unittest.skipIf(os.getenv("ONEFLOW_TEST_CPU_ONLY"), "only test cpu cases") | ||
@flow.unittest.skip_unless_1n2d() | ||
class TestGraphPipelineDelayOutput(oneflow.unittest.TestCase): | ||
def test_graph_pipeline_delay_output(test_case): | ||
_test_graph_pipeline_delay_output(test_case) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |
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.
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.
这个没有上下文的估计看不出在做什么,这里加注释说明下应该会更清楚
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.
好的