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

Method format_str

fastdeploy/model_executor/forward_meta.py:171–194  ·  view source on GitHub ↗

A helper function to recursively get a concise string representation of objects.

(obj)

Source from the content-addressed store, hash-verified

169 """
170
171 def format_str(obj):
172 """
173 A helper function to recursively get a concise string representation of objects.
174 """
175 if obj is None:
176 return "None"
177 elif isinstance(obj, paddle.Tensor):
178 tensor_info = {
179 "data_ptr": obj.data_ptr(),
180 "shape": obj.shape,
181 "dtype": str(obj.dtype),
182 "place": str(obj.place),
183 "content": obj if obj.numel() < 70 else "Too big to show",
184 }
185 return tensor_info
186 elif isinstance(obj, (list, tuple)):
187 return [format_str(item) for item in obj]
188 elif isinstance(obj, dict):
189 return {key: format_str(value) for key, value in obj.items()}
190 elif not isinstance(obj, (int, float, str, bool)) and hasattr(obj, "__dict__"):
191 info = {key: format_str(value) for key, value in obj.__dict__.items() if not key.startswith("_")}
192 return f"<{obj.__class__.__name__} object info: {info}>"
193 else:
194 return str(obj)
195
196 simplified_info = format_str(self.__dict__)
197 lines = [f" {key}: {value}" for key, value in simplified_info.items()]

Callers

nothing calls this directly

Calls 2

data_ptrMethod · 0.80
itemsMethod · 0.80

Tested by

no test coverage detected