This function gets the GFlags value in Paddle. For FLAGS please refer to :ref:`en_guides_flags_flags` Args: flags(list|tuple|str): A list/tuple of string or a string which is the flag's name. Returns: flag's value in Paddle. Examples: .. code-block:: p
(flags: str | Sequence[str])
| 161 | |
| 162 | |
| 163 | def get_flags(flags: str | Sequence[str]) -> dict[str, bool | str | float]: |
| 164 | """ |
| 165 | This function gets the GFlags value in Paddle. |
| 166 | For FLAGS please refer to :ref:`en_guides_flags_flags` |
| 167 | |
| 168 | Args: |
| 169 | flags(list|tuple|str): A list/tuple of string or a string which is the flag's name. |
| 170 | |
| 171 | Returns: |
| 172 | flag's value in Paddle. |
| 173 | |
| 174 | Examples: |
| 175 | .. code-block:: pycon |
| 176 | |
| 177 | >>> import paddle |
| 178 | |
| 179 | >>> flags = ['FLAGS_eager_delete_tensor_gb', 'FLAGS_check_nan_inf'] |
| 180 | >>> res = paddle.get_flags(flags) |
| 181 | >>> print(res) |
| 182 | {'FLAGS_eager_delete_tensor_gb': 0.0, 'FLAGS_check_nan_inf': False} |
| 183 | """ |
| 184 | flags_value = {} |
| 185 | if isinstance(flags, (list, tuple)): |
| 186 | for key in flags: |
| 187 | if _global_flags().is_public(key): |
| 188 | value = _global_flags()[key] |
| 189 | temp = {key: value} |
| 190 | flags_value.update(temp) |
| 191 | else: |
| 192 | raise ValueError( |
| 193 | f"Flag {key} cannot get its value through this function." |
| 194 | ) |
| 195 | elif isinstance(flags, str): |
| 196 | if _global_flags().is_public(flags): |
| 197 | value = _global_flags()[flags] |
| 198 | temp = {flags: value} |
| 199 | flags_value.update(temp) |
| 200 | else: |
| 201 | raise ValueError( |
| 202 | f"Flag {flags} cannot get its value through this function." |
| 203 | ) |
| 204 | else: |
| 205 | raise TypeError("Flags in get_flags should be a list, tuple or string.") |
| 206 | return flags_value |
| 207 | |
| 208 | |
| 209 | @contextmanager |