Get debug string. Args: throw_on_error (bool): True if raise an exception when self is not initialized. with_details (bool): more details about variables and parameters (e.g. trainable, optimize_attr, ...) will be printed when with_details is True. Default
(self, throw_on_error, with_details=False)
| 2205 | return var_str |
| 2206 | |
| 2207 | def to_string(self, throw_on_error, with_details=False): |
| 2208 | """ |
| 2209 | Get debug string. |
| 2210 | |
| 2211 | Args: |
| 2212 | |
| 2213 | throw_on_error (bool): True if raise an exception when self is not initialized. |
| 2214 | |
| 2215 | with_details (bool): more details about variables and parameters (e.g. trainable, optimize_attr, ...) will be printed when with_details is True. Default value is False; |
| 2216 | |
| 2217 | Returns: |
| 2218 | str: The debug string. |
| 2219 | |
| 2220 | Examples: |
| 2221 | .. code-block:: pycon |
| 2222 | |
| 2223 | >>> # doctest: +SKIP("This has diff in xdoctest env") |
| 2224 | >>> import paddle.base as base |
| 2225 | >>> import paddle |
| 2226 | |
| 2227 | >>> paddle.enable_static() |
| 2228 | >>> cur_program = base.Program() |
| 2229 | >>> cur_block = cur_program.current_block() |
| 2230 | >>> new_variable = cur_block.create_var( |
| 2231 | ... name="X", |
| 2232 | ... shape=[-1, 23, 48], |
| 2233 | ... dtype="float32", |
| 2234 | ... ) |
| 2235 | >>> print(new_variable.to_string(True)) |
| 2236 | >>> print("=============with detail===============") |
| 2237 | >>> print(new_variable.to_string(True, True)) |
| 2238 | name: "X" |
| 2239 | type { |
| 2240 | type: DENSE_TENSOR |
| 2241 | lod_tensor { |
| 2242 | tensor { |
| 2243 | data_type: FP32 |
| 2244 | dims: -1 |
| 2245 | dims: 23 |
| 2246 | dims: 48 |
| 2247 | } |
| 2248 | } |
| 2249 | } |
| 2250 | stop_gradient: false |
| 2251 | error_clip: None |
| 2252 | """ |
| 2253 | assert isinstance(throw_on_error, bool) and isinstance( |
| 2254 | with_details, bool |
| 2255 | ) |
| 2256 | protostr = self.desc.serialize_to_string() |
| 2257 | proto = framework_pb2.VarDesc.FromString(bytes(protostr)) |
| 2258 | res_str = _debug_string_(proto, throw_on_error) |
| 2259 | if with_details: |
| 2260 | additional_attr = ("error_clip",) |
| 2261 | for attr_name in additional_attr: |
| 2262 | res_str += f"{attr_name}: {getattr(self, attr_name)}\n" |
| 2263 | |
| 2264 | return res_str |
nothing calls this directly
no test coverage detected