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

Class InputBatch

fastdeploy/worker/input_batch.py:26–656  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25
26class InputBatch:
27 def __getitem__(self, key):
28 """Support dictionary-style attribute access"""
29 if hasattr(self, key):
30 return getattr(self, key)
31 raise KeyError(f"'{key}' is not a valid attribute of InputBatch")
32
33 def __setitem__(self, key, value):
34 """Support dictionary-style attribute setting, overwrite if exists, add if not exists"""
35 setattr(self, key, value)
36
37 def __contains__(self, key):
38 """Support 'in' operator to check if attribute exists"""
39 return hasattr(self, key)
40
41 def update(self, values: dict):
42 """Batch update attributes, similar to dict's update method"""
43 for key, value in values.items():
44 setattr(self, key, value)
45
46 def pop(self, key, default=None):
47 """
48 Pop an attribute, similar to dict's pop method
49
50 Args:
51 key: Name of the attribute to pop
52 default: Default value to return if attribute does not exist
53
54 Returns:
55 Popped attribute value, or default if attribute doesn't exist and default is provided
56 """
57 if hasattr(self, key):
58 value = getattr(self, key)
59 delattr(self, key)
60 return value
61 elif default is not None:
62 return default
63 else:
64 raise KeyError(f"'{key}' is not a valid attribute of InputBatch")
65
66 def __delitem__(self, key):
67 """
68 Delete an attribute using del operator
69
70 Args:
71 key: Name of the attribute to delete
72
73 Raises:
74 KeyError: If attribute does not exist
75 """
76 if hasattr(self, key):
77 delattr(self, key)
78 else:
79 raise KeyError(f"'{key}' is not a valid attribute of InputBatch")
80
81 def __init__(self, fd_config: FDConfig) -> None:
82 """
83 Initialize all share buffers for model inputs.

Callers 9

__init__Method · 0.90
__init__Method · 0.90
setup_model_runnerMethod · 0.90
setUpMethod · 0.90
setup_model_runnerMethod · 0.90
setup_methodMethod · 0.90

Calls

no outgoing calls

Tested by 6

setUpMethod · 0.72
setup_model_runnerMethod · 0.72
setup_methodMethod · 0.72