optimum/graphcore/trainer.py
def _wrap_model(self, model: Union[PreTrainedModel, PoplarExecutor], training=True) -> PoplarExecutor:
        """
        Wraps a model for poptorch, either for training or for inference.

        Args:
            model (`~transformers.modeling_utils.PreTrainedModel` or `PoplarExecutor`): the model to wrap
            training (`bool`, *optional*, defaults to `True`): whether to wrap the model for training or not.

        Returns:
            The wrapped model.

        """
        wrapped = None
        if isinstance(model, PoplarExecutor):
            wrapped = model
        elif training:
            if self.training_model is None:
                self.training_model = poptorch.trainingModel(
                    model.train(), options=self.opts, optimizer=self.optimizer
                )
            wrapped = self.training_model
        else:
            if self.inference_model is None:
                self.inference_model = poptorch.inferenceModel(model.eval(), options=self.eval_opts)
            wrapped = self.inference_model

        # Attaching to device when the model that is being access was already compiled but detached from previous loop.
        if wrapped.isCompiled() and not wrapped.isAttachedToDevice():
            wrapped.attachToDevice()
        return wrapped

        Wraps a model for poptorch, either for training or for inference.

        Args:
            model (`~transformers.modeling_utils.PreTrainedModel` or `PoplarExecutor`): the model to wrap
            training (`bool`, *optional*, defaults to `True`): whether to wrap the model for training or not.

        Returns:
            The wrapped model.

        
Wraps a model for poptorch, either for training or for inference.
Wraps a model for poptorch either for training or for inference .
def _wrap_model(self, model: Union[PreTrainedModel, PoplarExecutor], training=True) -> PoplarExecutor:
        wrapped = None
        if isinstance(model, PoplarExecutor):
            wrapped = model
        elif training:
            if self.training_model is None:
                self.training_model = poptorch.trainingModel(
                    model.train(), options=self.opts, optimizer=self.optimizer
                )
            wrapped = self.training_model
        else:
            if self.inference_model is None:
                self.inference_model = poptorch.inferenceModel(model.eval(), options=self.eval_opts)
            wrapped = self.inference_model
        if wrapped.isCompiled() and not wrapped.isAttachedToDevice():
            wrapped.attachToDevice()
        return wrapped
def _wrap_model ( self , model : Union [ PreTrainedModel , PoplarExecutor ] , training = True ) -> PoplarExecutor : wrapped = None if isinstance ( model , PoplarExecutor ) : wrapped = model elif training : if self . training_model is None : self . training_model = poptorch . trainingModel ( model . train ( ) , options = self . opts , optimizer = self . optimizer ) wrapped = self . training_model else : if self . inference_model is None : self . inference_model = poptorch . inferenceModel ( model . eval ( ) , options = self . eval_opts ) wrapped = self . inference_model if wrapped . isCompiled ( ) and not wrapped . isAttachedToDevice ( ) : wrapped . attachToDevice ( ) return wrapped
Wraps a model for poptorch, either for training or for inference.
Wraps a model for poptorch either for training or for inference .
"""
        Wraps a model for poptorch, either for training or for inference.

        Args:
            model (`~transformers.modeling_utils.PreTrainedModel` or `PoplarExecutor`): the model to wrap
            training (`bool`, *optional*, defaults to `True`): whether to wrap the model for training or not.

        Returns:
            The wrapped model.

        """ # Attaching to device when the model that is being access was already compiled but detached from previous loop.
The wrapped model.
The wrapped model .
self
model
Union[PreTrainedModel, PoplarExecutor]
the model to wrap
the model to wrap
training
whether to wrap the model for training or not.
whether to wrap the model for training or not .