MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / __init__

Method __init__

deepspeed/inference/engine.py:49–189  ·  view source on GitHub ↗

Args: model: torch.nn.Module config: DeepSpeedInferenceConfig

(self, model, config)

Source from the content-addressed store, hash-verified

47 expert_mp_group = None
48
49 def __init__(self, model, config):
50 """
51 Args:
52 model: torch.nn.Module
53 config: DeepSpeedInferenceConfig
54 """
55 global DS_INFERENCE_ENABLED
56 DS_INFERENCE_ENABLED = True
57
58 super().__init__()
59 if DeepSpeedTransformerInference.workspace is not None:
60 self.destroy()
61
62 self.module = model
63 self._config = config
64
65 self._get_model_config_generate(config) # keep for weird backward compatibility
66
67 # patch model generate with ours if model uses it
68 if hasattr(self.module, "generate"):
69 self.generate = self._generate
70
71 if hasattr(self.module, "config"):
72 TransformerPolicy.hf_model_config = self.module.config
73
74 if config.dtype not in get_accelerator().supported_dtypes():
75 raise ValueError(
76 f"Data type {config.dtype} is not supported by {get_accelerator().device_name()} accelerator")
77
78 # todo: keep this self.injection_dict because we don't use to change config.injection_policy API
79 # todo: this will get changed when Molly's PR on auto injection dict is merged
80 self.injection_dict = config.injection_policy
81
82 # todo: refactor the mp_group and mp_size related in the next refactor
83 self.mp_group = config.tensor_parallel.tp_group
84 self.mpu = config.tensor_parallel.mpu
85
86 self.quantize_merge_count = 1
87 self.quantization_scales = None
88
89 # these are not needed in the config as we are creating them ourselves in the inference engine
90 self.ep_group = None # config.moe.ep_group
91 self.expert_mp_group = None # config.moe.ep_mp_group
92
93 self.cuda_graph_created = False
94 self.checkpoint_engine = TorchCheckpointEngine()
95 quantization_setting = None
96 self._init_quantization_setting(
97 quantization_setting) # todo: update with the new quant config for weight quant
98 self.model_profile_enabled = False
99 self._model_times = []
100
101 if not self.injection_dict and config.replace_with_kernel_inject:
102 # This is a hack to remove the prepare_mask function on HF side for BLOOM architecture
103 self.remove_mask_prepare_for_bloom()
104
105 if get_accelerator().device_name() == 'cuda' and config.enable_cuda_graph:
106 assert pkg_version.parse(torch.__version__) >= pkg_version.parse("1.10"), \

Callers

nothing calls this directly

Calls 15

destroyMethod · 0.95
_convert_to_dtypeMethod · 0.95
build_alibi_tensorMethod · 0.95
build_attn_biasMethod · 0.95
get_acceleratorFunction · 0.90

Tested by

no test coverage detected