MCPcopy Create free account
hub / github.com/google-research/language / postprocess_fn

Method postprocess_fn

language/mentionmemory/tasks/base_task.py:203–221  ·  view source on GitHub ↗

Function that prepares model's input and output for serialization.

(batch: Dict[str, Any],
                       auxiliary_output: Dict[str, Any])

Source from the content-addressed store, hash-verified

201 """
202
203 def postprocess_fn(batch: Dict[str, Any],
204 auxiliary_output: Dict[str, Any]) -> Dict[str, Any]:
205 """Function that prepares model's input and output for serialization."""
206
207 features = {}
208 for dict_of_features in [batch, auxiliary_output]:
209 for key, value in dict_of_features.items():
210 convert_to_list = (
211 isinstance(value, Array) or isinstance(value, np.ndarray))
212 if convert_to_list and value.dtype == jnp.bfloat16:
213 # bfloat16 is not JSON serializable => convert to float32.
214 features[key] = value.astype(jnp.float32).tolist()
215 elif convert_to_list:
216 # Cannot serialize numpy / jax arrays to json => convert to list.
217 features[key] = value.tolist()
218 else:
219 features[key] = value
220
221 return features
222
223 return postprocess_fn

Callers 3

postprocessMethod · 0.45
postprocessMethod · 0.45
test_loss_fnMethod · 0.45

Calls

no outgoing calls

Tested by 1

test_loss_fnMethod · 0.36