text: # Copyright 2020 The ElasticDL Authors. All rights reserved.
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  #
  # http://www.apache.org/licenses/LICENSE-2.0
  #
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  from abc import abstractmethod
  
  
  class Trainer(object):
      """An abstract trainer to train/evaluate/predict using a minibatch data.
      The trainer will do forward and bachward computation, report gradients
      and update model variables.
      """
  
      @abstractmethod
      def init_variables_if_need(self, features, labels):
          """Initialize model variables before calling the model"""
          pass
  
      @abstractmethod
      def train_minibatch(features, labels, train_with_local_model):
          """Train the model using a minibatch data"""
          pass
  
      @abstractmethod
      def evaluate_minibatch(features, labels):
          """"Evaluate the model using a minibatch data"""
          pass
  
      @abstractmethod
      def predict_minibatch(features):
          """Model predicts using a minibatch data"""
          pass
  
      @abstractmethod
      def get_model_version(self):
          """Return the model iteration version"""
          pass
  
      @abstractmethod
      def get_evaluation_result(self):
          """Return the evaluation result"""
          pass
  
      @abstractmethod
      def reset_evaluation_result(self):
          """Reset the evaluation result"""
          pass
  