MCPcopy Create free account
hub / github.com/InternLM/InternBootcamp / _postprocess_common

Function _postprocess_common

verl/verl/utils/transferqueue_utils.py:208–241  ·  view source on GitHub ↗

Common post-processing logic for function outputs in TransferQueue bridge. This function handles the final return value based on whether data should be put into storage (put_data) and whether collection is needed (need_collect). It ensures proper return types based on the execution cont

(output, put_data, need_collect)

Source from the content-addressed store, hash-verified

206
207
208def _postprocess_common(output, put_data, need_collect):
209 """Common post-processing logic for function outputs in TransferQueue bridge.
210
211 This function handles the final return value based on whether data should be
212 put into storage (put_data) and whether collection is needed (need_collect).
213 It ensures proper return types based on the execution context.
214
215 Args:
216 output: The original output from the decorated function. Can be any type.
217 put_data: bool, indicating whether the output should be put into TransferQueue.
218 If True, output will be put to TQ and return the corresponding BatchMeta;
219 if False, output will not be put into TQ.
220 need_collect: bool, indicating whether this process needs to collect data.
221 If False, the output will be replaced by an empty BatchMeta or DataProto
222 to avoid redundant communication.
223
224 Returns:
225 - BatchMeta.empty(): When put_data=True but need_collect=False, indicating
226 no data should be stored but BatchMeta structure is expected.
227 - DataProto(): When put_data=False, need_collect=False, and output is DataProto,
228 returning an empty DataProto.
229 - output: In all other cases, returns the original output unchanged.
230
231 Note:
232 This function is used in the tqbridge decorator to normalize return values
233 across different execution paths and avoid redundant data operations in
234 distributed scenarios.
235 """
236 if put_data and not need_collect:
237 return BatchMeta.empty()
238 elif not put_data and not need_collect and isinstance(output, DataProto):
239 return DataProto()
240 else:
241 return output
242
243
244def tqbridge(dispatch_mode: "dict | Dispatch" = None, put_data: bool = True):

Callers 2

innerFunction · 0.85
async_innerFunction · 0.85

Calls 1

DataProtoClass · 0.90

Tested by

no test coverage detected