MCPcopy Create free account
hub / github.com/PaddlePaddle/FastDeploy / get_pooling_config

Function get_pooling_config

fastdeploy/transformer_utils/config.py:99–139  ·  view source on GitHub ↗

This function gets the pooling and normalize config from the model - only applies to sentence-transformers models. Args: model (str): The name of the Hugging Face model. revision (str, optional): The specific version of the model to use. Defaults to 'main'.

(model: str, revision: Optional[str] = "main")

Source from the content-addressed store, hash-verified

97
98
99def get_pooling_config(model: str, revision: Optional[str] = "main"):
100 """
101 This function gets the pooling and normalize
102 config from the model - only applies to
103 sentence-transformers models.
104
105 Args:
106 model (str): The name of the Hugging Face model.
107 revision (str, optional): The specific version
108 of the model to use. Defaults to 'main'.
109
110 Returns:
111 dict: A dictionary containing the pooling
112 type and whether normalization is used.
113 """
114
115 modules_file_name = "modules.json"
116 modules_dict = None
117 if file_or_path_exists(model, config_name=modules_file_name):
118 modules_dict = get_hf_file_to_dict(modules_file_name, model)
119
120 if modules_dict is None:
121 return None
122
123 pooling = next((item for item in modules_dict if item["type"] == "sentence_transformers.models.Pooling"), None)
124
125 normalize = bool(
126 next((item for item in modules_dict if item["type"] == "sentence_transformers.models.Normalize"), False)
127 )
128
129 if pooling:
130 pooling_file_name = "{}/config.json".format(pooling["path"])
131 pooling_dict = get_hf_file_to_dict(pooling_file_name, model)
132 pooling_type_name = next((item for item, val in pooling_dict.items() if val is True), None)
133
134 if pooling_type_name is not None:
135 pooling_type_name = get_pooling_config_name(pooling_type_name)
136
137 return {"pooling_type": pooling_type_name, "normalize": normalize}
138
139 return None

Callers 3

_init_pooler_configMethod · 0.90
load_weightsMethod · 0.90

Calls 5

file_or_path_existsFunction · 0.85
get_hf_file_to_dictFunction · 0.85
get_pooling_config_nameFunction · 0.85
itemsMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected