Args: model: torch.nn.Module config: DeepSpeedInferenceConfig
(self, model, config)
| 92 | expert_mp_group = None |
| 93 | |
| 94 | def __init__(self, model, config): |
| 95 | """ |
| 96 | Args: |
| 97 | model: torch.nn.Module |
| 98 | config: DeepSpeedInferenceConfig |
| 99 | """ |
| 100 | global DS_INFERENCE_ENABLED |
| 101 | DS_INFERENCE_ENABLED = True |
| 102 | |
| 103 | super().__init__() |
| 104 | |
| 105 | self.module = model |
| 106 | self._config = config |
| 107 | |
| 108 | self._get_model_config_generate(config) # keep for weird backward compatibility |
| 109 | |
| 110 | # patch model generate with ours if model uses it |
| 111 | if hasattr(self.module, "generate"): |
| 112 | self.generate = self._generate |
| 113 | |
| 114 | if hasattr(self.module, "config"): |
| 115 | TransformerPolicy.hf_model_config = self.module.config |
| 116 | |
| 117 | # todo: keep this self.injection_dict because we don't use to change config.injection_policy API |
| 118 | # todo: this will get changed when Molly's PR on auto injection dict is merged |
| 119 | self.injection_dict = config.injection_policy |
| 120 | |
| 121 | # todo: refactor the mp_group and mp_size related in the next refactor |
| 122 | self.mp_group = config.tensor_parallel.tp_group |
| 123 | self.mpu = config.tensor_parallel.mpu |
| 124 | |
| 125 | #self._validate_args(self.mpu, config.replace_with_kernel_inject) |
| 126 | self.quantize_merge_count = 1 |
| 127 | self.quantization_scales = None |
| 128 | |
| 129 | # these are not needed in the config as we are creating them ourselves in the inference engine |
| 130 | self.ep_group = None # config.moe.ep_group |
| 131 | self.expert_mp_group = None # config.moe.ep_mp_group |
| 132 | |
| 133 | self.cuda_graph_created = False |
| 134 | self.checkpoint_engine = TorchCheckpointEngine() |
| 135 | quantization_setting = None |
| 136 | self._init_quantization_setting( |
| 137 | quantization_setting) # todo: update with the new quant config for weight quant |
| 138 | self.model_profile_enabled = False |
| 139 | self._model_times = [] |
| 140 | |
| 141 | if not self.injection_dict and config.replace_with_kernel_inject: |
| 142 | # This is a hack to remove the prepare_mask function on HF side for BLOOM architecture |
| 143 | self.remove_mask_prepare_for_bloom() |
| 144 | |
| 145 | if self.injection_dict or not config.replace_with_kernel_inject: |
| 146 | # This is a hack to redefine the alibi func due to TP |
| 147 | if config.tensor_parallel.tp_size > 1: |
| 148 | self.build_alibi_tensor() |
| 149 | |
| 150 | if get_accelerator().device_name() == 'cuda' and config.enable_cuda_graph: |
| 151 | assert pkg_version.parse(torch.__version__) >= pkg_version.parse("1.10"), \ |
nothing calls this directly
no test coverage detected