-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Microbatch first last batch serial #11072
Merged
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
0d61609
microbatch: split out first and last batch to run in serial
MichelleArk bec5d57
use Task.get_runner
MichelleArk 32002ea
only run pre_hook on first batch, post_hook on last batch
MichelleArk 37dbd11
refactor: internalize parallel to RunTask._submit_batch
MichelleArk 23271b9
Add optional `force_sequential` to `_submit_batch` to allow for skipp…
QMalcolm 9c903f7
Force last batch to run sequentially
QMalcolm e624057
Force first batch to run sequentially
QMalcolm 0c2e327
Fixup
QMalcolm a37f3a6
Remove batch_idx check in `should_run_in_parallel`
QMalcolm cfe1dcf
Begin skipping batches if first batch fails
QMalcolm 8424209
Write custom `on_skip` for `MicrobatchModelRunner` to better handle w…
QMalcolm 50abb45
Add microbatch pre-hook, post-hook, and sequential first/last batch t…
QMalcolm 9bc3816
Fix/Add tests around first batch failure vs latter batch failure
QMalcolm 7699f52
Fix MicrobatchModelRunner.on_skip to handle skipping the entire node
QMalcolm 74a76c4
Fix conditional logic for setting pre and post hooks for batches
QMalcolm 0c16d07
Revert back to using the MicrobatchModelRunner initializer directly
QMalcolm 3fa7bbc
Add two new event types `LogStartBatch` and `LogBatchResult`
QMalcolm f4315ef
Update MicrobatchModelRunner to use new batch specific log events
QMalcolm bec65b8
Fix event testing
QMalcolm c0743e0
Update microbatch integrationt tests to catch batch specific event types
QMalcolm 0198741
Add changie doc
QMalcolm 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 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 |
---|---|---|
|
@@ -602,15 +602,15 @@ | |
) | ||
return relation is not None | ||
|
||
def _should_run_in_parallel( | ||
self, | ||
relation_exists: bool, | ||
) -> bool: | ||
def should_run_in_parallel(self) -> bool: | ||
if not self.adapter.supports(Capability.MicrobatchConcurrency): | ||
run_in_parallel = False | ||
elif not relation_exists: | ||
elif not self.relation_exists: | ||
# If the relation doesn't exist, we can't run in parallel | ||
run_in_parallel = False | ||
elif self.batch_idx == 0 or self.batch_idx == len(self.batches) - 1: | ||
# First and last batch don't run in parallel | ||
run_in_parallel = False | ||
elif self.node.config.concurrent_batches is not None: | ||
# If the relation exists and the `concurrent_batches` config isn't None, use the config value | ||
run_in_parallel = self.node.config.concurrent_batches | ||
|
@@ -705,42 +705,30 @@ | |
) -> RunResult: | ||
# Initial run computes batch metadata | ||
result = self.call_runner(runner) | ||
batches = runner.batches | ||
node = runner.node | ||
relation_exists = runner.relation_exists | ||
batches, node, relation_exists = runner.batches, runner.node, runner.relation_exists | ||
|
||
# Return early if model should be skipped, or there are no batches to execute | ||
if result.status == RunStatus.Skipped: | ||
return result | ||
elif len(runner.batches) == 0: | ||
return result | ||
|
||
batch_results: List[RunResult] = [] | ||
batch_idx = 0 | ||
|
||
# Run first batch runs in serial | ||
relation_exists = self._submit_batch( | ||
node, relation_exists, batches, batch_idx, batch_results, pool, parallel=False | ||
) | ||
batch_idx += 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's actually preferable to the first batch separated out. It makes it mirror how the last batch is separated out. We could also have an optional arg |
||
|
||
# Subsequent batches can be run in parallel | ||
# Run all batches except last batch, in parallel if possible | ||
while batch_idx < len(runner.batches) - 1: | ||
parallel = runner._should_run_in_parallel(relation_exists) | ||
relation_exists = self._submit_batch( | ||
node, relation_exists, batches, batch_idx, batch_results, pool, parallel | ||
node, relation_exists, batches, batch_idx, batch_results, pool | ||
) | ||
batch_idx += 1 | ||
|
||
# Wait until all submitted batches have completed | ||
while len(batch_results) != batch_idx: | ||
pass | ||
# Final batch runs once all others complete to ensure post_hook runs at the end | ||
self._submit_batch(node, relation_exists, batches, batch_idx, batch_results, pool) | ||
|
||
# Final batch runs in serial | ||
self._submit_batch( | ||
node, relation_exists, batches, batch_idx, batch_results, pool, parallel=False | ||
) | ||
|
||
# Finalize run: merge results, track model run, and print final result line | ||
runner.merge_batch_results(result, batch_results) | ||
track_model_run(runner.node_index, runner.num_nodes, result, adapter=runner.adapter) | ||
runner.print_result_line(result) | ||
|
@@ -755,7 +743,6 @@ | |
batch_idx: int, | ||
batch_results: List[RunResult], | ||
pool: ThreadPool, | ||
parallel: bool, | ||
): | ||
node_copy = deepcopy(node) | ||
# Only run pre_hook(s) for first batch | ||
|
@@ -764,14 +751,14 @@ | |
# Only run post_hook(s) for last batch | ||
elif batch_idx != len(batches) - 1: | ||
node_copy.config.post_hook = [] | ||
|
||
batch_runner = self.get_runner(node_copy) | ||
assert isinstance(batch_runner, MicrobatchModelRunner) | ||
batch_runner.set_batch_idx(batch_idx) | ||
batch_runner.set_relation_exists(relation_exists) | ||
batch_runner.set_batches(batches) | ||
|
||
if parallel: | ||
if batch_runner.should_run_in_parallel(): | ||
fire_event( | ||
MicrobatchExecutionDebug( | ||
msg=f"{batch_runner.describe_batch} is being run concurrently" | ||
|
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
Oops, something went wrong.
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.
This check could also be skipped if we're instead handling
force_sequential
to determine if we should even checkshould_run_in_parallel
in_submit_batch
. It'd be nice for this function to be less dependent on "where" it is, and I think this check breaks that.