-
Notifications
You must be signed in to change notification settings - Fork 56
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
Move hash computation so that it is recomputed on retry, and now-inva… #258
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
"""Single run of remove-background, given input arguments.""" | ||
|
||
import cellbender | ||
from cellbender.remove_background.model import RemoveBackgroundPyroModel | ||
from cellbender.remove_background.data.dataset import get_dataset_obj, \ | ||
SingleCellRNACountsDataset | ||
|
@@ -21,6 +22,7 @@ | |
from cellbender.remove_background.sparse_utils import csr_set_rows_to_zero | ||
from cellbender.remove_background.data.io import write_matrix_to_cellranger_h5 | ||
from cellbender.remove_background.report import run_notebook_make_html, plot_summary | ||
from cellbender.remove_background.checkpoint import create_workflow_hashcode | ||
|
||
import pyro | ||
from pyro.infer import SVI, JitTraceEnum_ELBO, JitTrace_ELBO, \ | ||
|
@@ -59,6 +61,22 @@ def run_remove_background(args: argparse.Namespace) -> Posterior: | |
|
||
""" | ||
|
||
# Set up checkpointing by creating a unique workflow hash. | ||
hashcode = create_workflow_hashcode( | ||
module_path=os.path.dirname(cellbender.__file__), | ||
args_to_remove=(['output_file', 'fpr', 'input_checkpoint_tarball', 'debug', | ||
'posterior_batch_size', 'checkpoint_min', 'truth_file', | ||
'posterior_regularization', 'cdf_threshold_q', 'prq_alpha', | ||
'estimator', 'use_multiprocessing_estimation', 'cpu_threads', | ||
# The following settings do not affect the results, and can change when retrying, | ||
# so remove them. | ||
'epoch_elbo_fail_fraction', 'final_elbo_fail_fraction', | ||
'num_failed_attempts', 'checkpoint_filename'] | ||
+ (['epochs'] if args.constant_learning_rate else [])), | ||
args=args)[:10] | ||
args.checkpoint_filename = hashcode # store this in args | ||
logger.info(f'(Workflow hash {hashcode})') | ||
|
||
# Handle initial random state. | ||
pyro.util.set_rng_seed(consts.RANDOM_SEED) | ||
if torch.cuda.is_available(): | ||
|
@@ -771,7 +789,12 @@ def run_inference(dataset_obj: SingleCellRNACountsDataset, | |
sys.exit(0) | ||
else: | ||
logger.info(f'No more attempts are specified by --num-training-tries. ' | ||
f'Therefore the workflow will abort here.') | ||
f'Therefore the workflow will run once more without ELBO restrictions.') | ||
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. Do you want to re-run it? Does this re-run "cache", i.e. use the checkpoint? Or does it actually retrain the whole thing? 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. Yes, after the changes to the elements that are included in the hash computation, this uses the most recent checkpoint. 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. Awesome, sounds perfect |
||
args.epoch_elbo_fail_fraction = None | ||
args.final_elbo_fail_fraction = None | ||
run_remove_background(args) # start from scratch | ||
# non-zero exit status in order to draw user's attention to the fact that ELBO tests | ||
# were never satisfied. | ||
sys.exit(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 can see the value of still wanting to exit 1 so that the run will be flagged as a failure |
||
|
||
logger.info("Inference procedure complete.") | ||
|
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.
Thank you! These had been overlooked by me