Get the value of variable or value in given scope. Args: scope(Scope, optional) : If `scope` is None, it will be set to global scope obtained through 'paddle.static.global_scope()'. Otherwise, use `scope`. Default: None Returns: Tensor, the valu
(var, scope=None)
| 346 | |
| 347 | |
| 348 | def get_value(var, scope=None): |
| 349 | """ |
| 350 | Get the value of variable or value in given scope. |
| 351 | |
| 352 | Args: |
| 353 | scope(Scope, optional) : If `scope` is None, it will be set to global scope |
| 354 | obtained through 'paddle.static.global_scope()'. Otherwise, use `scope`. |
| 355 | Default: None |
| 356 | |
| 357 | Returns: |
| 358 | Tensor, the value in given scope. |
| 359 | |
| 360 | """ |
| 361 | if scope is not None and not isinstance(scope, core._Scope): |
| 362 | raise TypeError( |
| 363 | f"`scope` should be None or `paddle.static.Scope` type, but received {type(scope)}." |
| 364 | ) |
| 365 | |
| 366 | if scope is None: |
| 367 | scope = global_scope() |
| 368 | var_temp = scope.find_var(var.name) |
| 369 | if var_temp is None: |
| 370 | raise ValueError(f"Can not find Variable '{var.name}' in the Scope.") |
| 371 | t = var_temp.get_tensor() |
| 372 | return t |
| 373 | |
| 374 | |
| 375 | def is_pir_fetch_var(value): |