--- /content/alphafold_copy/alphafold/model/model.py 2022-06-21 02:56:28.903256585 +0000 +++ /content/alphafold/alphafold/model/model.py 2022-06-21 03:08:21.392362049 +0000 @@ -50,7 +50,8 @@ def __init__(self, config: ml_collections.ConfigDict, - params: Optional[Mapping[str, Mapping[str, np.ndarray]]] = None): + params: Optional[Mapping[str, Mapping[str, np.ndarray]]] = None, + is_training = False): self.config = config self.params = params @@ -58,7 +59,7 @@ model = modules.AlphaFold(self.config.model) return model( batch, - is_training=False, + is_training=is_training, compute_loss=False, ensemble_representations=True) @@ -117,7 +118,7 @@ logging.info('Output shape was %s', shape) return shape - def predict(self, feat: features.FeatureDict) -> Mapping[str, Any]: + def predict(self, feat: features.FeatureDict, random_seed=0) -> Mapping[str, Any]: """Makes a prediction by inferencing the model on the provided features. Args: @@ -128,14 +129,28 @@ A dictionary of model outputs. """ self.init_params(feat) - logging.info('Running predict with shape(feat) = %s', - tree.map_structure(lambda x: x.shape, feat)) - result = self.apply(self.params, jax.random.PRNGKey(0), feat) - # This block is to ensure benchmark timings are accurate. Some blocking is - # already happening when computing get_confidence_metrics, and this ensures - # all outputs are blocked on. - jax.tree_map(lambda x: x.block_until_ready(), result) - result.update(get_confidence_metrics(result)) - logging.info('Output shape was %s', - tree.map_structure(lambda x: x.shape, result)) - return result + logging.info('Running predict with shape(feat) = %s', tree.map_structure(lambda x: x.shape, feat)) + + aatype = feat["aatype"] + num_iters = self.config.model.num_recycle + 1 + num_ensemble = self.config.data.eval.num_ensemble + L = aatype.shape[1] + result = {"prev":{'prev_msa_first_row': np.zeros([L,256]), + 'prev_pair': np.zeros([L,L,128]), + 'prev_pos': np.zeros([L,37,3])}} + + r = 0 + key = jax.random.PRNGKey(random_seed) + while r < num_iters: + s = r * num_ensemble + e = (r+1) * num_ensemble + sub_feat = jax.tree_map(lambda x:x[s:e], feat) + sub_feat["prev"] = result["prev"] + result, _ = self.apply(self.params, key, sub_feat) + del sub_feat + confidences = get_confidence_metrics(result) + result.update(confidences) + r += 1 + + logging.info('Output shape was %s', tree.map_structure(lambda x: x.shape, result)) + return result, (r-1,0)