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

Move hash computation so that it is recomputed on retry, and now-inva… #258

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions cellbender/remove_background/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,6 @@ def setup_and_logging(args):
+ ' '.join(['cellbender', 'remove-background'] + sys.argv[2:]))
logger.info("CellBender " + get_version())

# 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']
+ (['epochs'] if args.constant_learning_rate else [])),
args=args)[:10]
args.checkpoint_filename = hashcode # store this in args
logger.info(f'(Workflow hash {hashcode})')
return args, file_handler


Expand Down
25 changes: 24 additions & 1 deletion cellbender/remove_background/run.py
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
Expand All @@ -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, \
Expand Down Expand Up @@ -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']
Comment on lines +71 to +74
Copy link
Member

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

+ (['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():
Expand Down Expand Up @@ -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.')
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

Copy link
Member

Choose a reason for hiding this comment

The 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)
Copy link
Member

Choose a reason for hiding this comment

The 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.")
Expand Down