sima_utils.transformer.model.base ================================= .. py:module:: sima_utils.transformer.model.base Classes ------- .. autoapisummary:: sima_utils.transformer.model.base.FileGenMode sima_utils.transformer.model.base.FileGenPrecision sima_utils.transformer.model.base.EvalMode sima_utils.transformer.model.base.BaseModel Module Contents --------------- .. py:class:: FileGenMode File generation mode. .. py:attribute:: ONNX .. py:attribute:: MODEL_SDK_QUANTIZE .. py:attribute:: MODEL_SDK_COMPILE .. py:attribute:: DEVKIT .. py:attribute:: ALL .. py:class:: FileGenPrecision Precision used when generating files. .. py:attribute:: BF16 :value: 'bf16' .. py:attribute:: A_BF16_W_INT8 :value: 'a_bf16_w_int8' .. py:attribute:: A_BF16_W_INT4 :value: 'a_bf16_w_int4' .. py:class:: EvalMode Model evaluation mode. .. py:attribute:: HF :value: 'hf' .. py:attribute:: ONNX :value: 'onnx' .. py:attribute:: SDK :value: 'sdk' .. py:class:: BaseModel Base implementation for visual-language model file generation. .. attribute:: cfg Configuration of the model. .. attribute:: model_name Name of the model. This will be used to determine the generated files' names. .. attribute:: onnx_path Path to store the ONNX files. .. attribute:: sima_path Path to store the SiMa-specific files. .. attribute:: hf_model LocalHuggingFaceModel object for obtaining the parameters to generate ONNX files. .. attribute:: onnx_file_name File name of the generated ONNX file. .. attribute:: weight_prefix The prefix of weight tensor names in the source model. .. py:attribute:: cfg :type: sima_utils.transformer.vlm_config.BaseConfig .. py:attribute:: model_name :type: str .. py:attribute:: onnx_path :type: pathlib.Path :value: 'onnx_files' .. py:attribute:: sima_path :type: pathlib.Path :value: 'sima_files' .. py:attribute:: hf_model :type: sima_utils.transformer.hf_transformer.LocalHuggingFaceModel | None :value: None .. py:attribute:: vlm_helper :type: sima_utils.transformer.vlm_config.VlmHelper | None :value: None .. py:method:: gen_files(gen_mode: FileGenMode, *, precision: FileGenPrecision = FileGenPrecision.BF16, log_level: int = logging.NOTSET, resume: bool = False) Generates files based on the provided file generation mode. :param gen_mode: File generation mode. :param precision: The precision to be used for Model SDK quantization mode. :param log_level: Logging level. :param resume: Set to generate only when the file cannot be found. .. py:method:: run_model(eval_mode: EvalMode, ifms: list[numpy.ndarray]) -> list[numpy.ndarray] Runs the model based on the evaluation mode. .. py:property:: vision_model_name :type: str .. py:property:: language_model_name :type: str .. py:property:: onnx_file_name :type: pathlib.Path .. py:property:: sima_model_sdk_path :type: pathlib.Path Path to the generated quantized Model SDK files. .. py:property:: sima_mpk_path :type: pathlib.Path Path to the generated MPK files. .. py:property:: sdk_file_name :type: pathlib.Path Path to the generated quantized Model SDK file. .. py:property:: mpk_file_name :type: pathlib.Path Path to the generated quantized Model SDK file. .. py:property:: sima_devkit_path :type: pathlib.Path Path to the generated files for DEVKIT. .. py:method:: get_gen_file_name(gen_mode: FileGenMode) -> pathlib.Path .. py:method:: gen_onnx_files() Generates ONNX files. .. py:method:: gen_model_sdk_files(precision: FileGenPrecision, log_level: int) Generates quantized Model SDK files. :param precision: Precision used for quantization. :param log_level: Logging level. .. py:method:: gen_mpk_files(log_level: int) -> afe.apis.model.Model Generates MPK files. :param log_level: Logging level. .. py:method:: gen_devkit_files(resume: bool = False) Generates files for devkit. .. py:method:: check_hf_param(name: str) -> bool Checks if a parameter tensor exists in the LocalHuggingFaceModel object. :param name: Full name of the parameter. :returns: True if the parameter tensor exists. .. py:method:: get_hf_param(name: str) -> numpy.ndarray Gets the parameter tensor from the LocalHuggingFaceModel object. :param name: Full name of the parameter. :returns: The parameter tensor in numpy array. .. py:method:: create_onnx_builder() Creates onnx builder. .. py:method:: gen_files_from_model_list(model_list: list[tuple[BaseModel, FileGenPrecision]], gen_mode: FileGenMode, num_processes: int, log_level: int, resume: bool)