graphinvent/Workflow.py
def learning_step(self) -> None:
        """
        Performs one fine-tuning step.
        """
        print(f"* Learning step {self.current_epoch}.", flush=True)
        self.agent_model.train()  # ensure model is in train mode
        self.agent_model.zero_grad()
        self.optimizer.zero_grad()

        self.prior_model.eval()
        self.basf_model.eval()

        # genereate molecules with agent model
        loss_a, score_a = self.generate_graphs_rl(model_a=self.agent_model,
                                                  model_b=self.prior_model,
                                                  is_agent=True,
                                                  model_a_label="agent")

        # generate molecules with best agent so far ("basf")
        loss_b, _ = self.generate_graphs_rl(model_a=self.basf_model,
                                            model_b=self.agent_model,
                                            is_agent=True,
                                            model_a_label="BASF")

        loss = (
            (1 - self.constants.alpha) * loss_a + self.constants.alpha * loss_b
        )

        # backpropagate
        loss.backward()
        self.optimizer.step()

        # update the learning rate
        self.scheduler.step()

        util.write_training_status(
            epoch=self.current_epoch,
            lr=self.optimizer.param_groups[0]["lr"],
            training_loss=torch.clone(loss),
            validation_loss=0.0,  # placeholder, not meaningful during fine-tuning
            score=torch.mean(torch.clone(score_a)).item()
        )

        self.rl_step += 1

        Performs one fine-tuning step.
        
Performs one fine-tuning step.
Performs one fine - tuning step .
def learning_step(self) -> None:
        print(f"* Learning step {self.current_epoch}.", flush=True)
        self.agent_model.train()  
        self.agent_model.zero_grad()
        self.optimizer.zero_grad()
        self.prior_model.eval()
        self.basf_model.eval()
        loss_a, score_a = self.generate_graphs_rl(model_a=self.agent_model,
                                                  model_b=self.prior_model,
                                                  is_agent=True,
                                                  model_a_label="agent")
        loss_b, _ = self.generate_graphs_rl(model_a=self.basf_model,
                                            model_b=self.agent_model,
                                            is_agent=True,
                                            model_a_label="BASF")
        loss = (
            (1 - self.constants.alpha) * loss_a + self.constants.alpha * loss_b
        )
        loss.backward()
        self.optimizer.step()
        self.scheduler.step()
        util.write_training_status(
            epoch=self.current_epoch,
            lr=self.optimizer.param_groups[0]["lr"],
            training_loss=torch.clone(loss),
            validation_loss=0.0,  
            score=torch.mean(torch.clone(score_a)).item()
        )
        self.rl_step += 1
def learning_step ( self ) -> None : print ( f"* Learning step {self.current_epoch}." , flush = True ) self . agent_model . train ( ) self . agent_model . zero_grad ( ) self . optimizer . zero_grad ( ) self . prior_model . eval ( ) self . basf_model . eval ( ) loss_a , score_a = self . generate_graphs_rl ( model_a = self . agent_model , model_b = self . prior_model , is_agent = True , model_a_label = "agent" ) loss_b , _ = self . generate_graphs_rl ( model_a = self . basf_model , model_b = self . agent_model , is_agent = True , model_a_label = "BASF" ) loss = ( ( 1 - self . constants . alpha ) * loss_a + self . constants . alpha * loss_b ) loss . backward ( ) self . optimizer . step ( ) self . scheduler . step ( ) util . write_training_status ( epoch = self . current_epoch , lr = self . optimizer . param_groups [ 0 ] [ "lr" ] , training_loss = torch . clone ( loss ) , validation_loss = 0.0 , score = torch . mean ( torch . clone ( score_a ) ) . item ( ) ) self . rl_step += 1
Performs one fine-tuning step.
Performs one fine - tuning step .
"""
        Performs one fine-tuning step.
        """ # ensure model is in train mode # genereate molecules with agent model # generate molecules with best agent so far ("basf") # backpropagate # update the learning rate # placeholder, not meaningful during fine-tuning
self