def build_ranking_serving_module( self, actor: ModelBase, state_normalization_data: NormalizationData, candidate_normalization_data: NormalizationData, num_candidates: int, action_normalization_data: NormalizationData, ) -> torch.nn.Module: state_preprocessor = Preprocessor( state_normalization_data.dense_normalization_parameters, use_gpu=False) candidate_preprocessor = Preprocessor( candidate_normalization_data.dense_normalization_parameters, use_gpu=False) postprocessor = Postprocessor( action_normalization_data.dense_normalization_parameters, use_gpu=False) actor_with_preprocessor = RankingActorWithPreprocessor( model=actor.cpu_model().eval(), state_preprocessor=state_preprocessor, candidate_preprocessor=candidate_preprocessor, num_candidates=num_candidates, action_postprocessor=postprocessor, ) action_features = Preprocessor( action_normalization_data.dense_normalization_parameters, use_gpu=False).sorted_features return RankingActorPredictorWrapper(actor_with_preprocessor, action_features)
def build_serving_module( self, actor: ModelBase, state_normalization_data: NormalizationData, action_normalization_data: NormalizationData, ) -> torch.nn.Module: """ Returns a TorchScript predictor module """ state_normalization_parameters = ( state_normalization_data.dense_normalization_parameters) action_normalization_parameters = ( action_normalization_data.dense_normalization_parameters) assert state_normalization_parameters is not None assert action_normalization_parameters is not None state_preprocessor = Preprocessor(state_normalization_parameters, use_gpu=False) postprocessor = Postprocessor(action_normalization_parameters, use_gpu=False) actor_with_preprocessor = ActorWithPreprocessor( actor.cpu_model().eval(), state_preprocessor, postprocessor) action_features = Preprocessor(action_normalization_parameters, use_gpu=False).sorted_features return ActorPredictorWrapper(actor_with_preprocessor, action_features)
def build_serving_module( self, actor: ModelBase, state_feature_config: rlt.ModelFeatureConfig, state_normalization_data: NormalizationData, action_normalization_data: NormalizationData, serve_mean_policy: bool = False, ) -> torch.nn.Module: """ Returns a TorchScript predictor module """ state_preprocessor = Preprocessor( state_normalization_data.dense_normalization_parameters, use_gpu=False) postprocessor = Postprocessor( action_normalization_data.dense_normalization_parameters, use_gpu=False) actor_with_preprocessor = ActorWithPreprocessor( actor.cpu_model().eval(), state_preprocessor, state_feature_config, postprocessor, serve_mean_policy=serve_mean_policy, ) action_features = Preprocessor( action_normalization_data.dense_normalization_parameters, use_gpu=False).sorted_features return ActorPredictorWrapper(actor_with_preprocessor, state_feature_config, action_features)
def build_serving_module( self, q_network: ModelBase, state_normalization_data: NormalizationData, action_names: List[str], state_feature_config: rlt.ModelFeatureConfig, ) -> torch.nn.Module: """ Returns a TorchScript predictor module """ state_preprocessor = Preprocessor( state_normalization_data.dense_normalization_parameters, False) dqn_with_preprocessor = DiscreteDqnWithPreprocessor( q_network.cpu_model().eval(), state_preprocessor) return DiscreteDqnPredictorWrapper(dqn_with_preprocessor, action_names, state_feature_config)
def build_serving_module( self, q_network: ModelBase, state_normalization_parameters: Dict[int, NormalizationParameters], action_normalization_parameters: Dict[int, NormalizationParameters], ) -> torch.nn.Module: """ Returns a TorchScript predictor module """ state_preprocessor = Preprocessor(state_normalization_parameters, False) action_preprocessor = Preprocessor(action_normalization_parameters, False) dqn_with_preprocessor = ParametricDqnWithPreprocessor( q_network.cpu_model().eval(), state_preprocessor, action_preprocessor ) return ParametricDqnPredictorWrapper( dqn_with_preprocessor=dqn_with_preprocessor )
def build_serving_module( self, actor: ModelBase, state_normalization_data: NormalizationData, action_feature_ids: List[int], ) -> torch.nn.Module: """ Returns a TorchScript predictor module """ state_preprocessor = Preprocessor( state_normalization_data.dense_normalization_parameters, use_gpu=False ) actor_with_preprocessor = ActorWithPreprocessor( actor.cpu_model().eval(), state_preprocessor, ) return ActorPredictorWrapper(actor_with_preprocessor, action_feature_ids)
def build_binary_difference_scorer( self, q_network: ModelBase, state_normalization_data: NormalizationData, action_names: List[str], state_feature_config: rlt.ModelFeatureConfig, ) -> torch.nn.Module: """ Returns softmax(1) - softmax(0) """ assert len(action_names) == 2 state_preprocessor = Preprocessor( state_normalization_data.dense_normalization_parameters, False) binary_difference_scorer_with_preprocessor = ( BinaryDifferenceScorerWithPreprocessor( q_network.cpu_model().eval(), state_preprocessor, state_feature_config)) return BinaryDifferenceScorerPredictorWrapper( binary_difference_scorer_with_preprocessor, state_feature_config)
def build_serving_module( self, q_network: ModelBase, state_normalization_parameters: Dict[int, NormalizationParameters], action_names: List[str], state_feature_config: rlt.ModelFeatureConfig, ) -> torch.nn.Module: """ Returns a TorchScript predictor module """ state_preprocessor = Preprocessor(state_normalization_parameters, False) dqn_with_preprocessor = DiscreteDqnWithPreprocessor( torch.nn.Sequential( # type: ignore q_network.cpu_model().eval(), _Mean()), state_preprocessor, ) return DiscreteDqnPredictorWrapper(dqn_with_preprocessor, action_names, state_feature_config)