Return the parameter given by ``target`` if it exists, otherwise throw an error. See the docstring for ``get_submodule`` for a more detailed explanation of this method's functionality as well as how to correctly specify ``target``. Args: target: The full
(self, target: str)
| 690 | return mod |
| 691 | |
| 692 | def get_parameter(self, target: str) -> "Parameter": |
| 693 | """Return the parameter given by ``target`` if it exists, otherwise throw an error. |
| 694 | |
| 695 | See the docstring for ``get_submodule`` for a more detailed |
| 696 | explanation of this method's functionality as well as how to |
| 697 | correctly specify ``target``. |
| 698 | |
| 699 | Args: |
| 700 | target: The fully-qualified string name of the Parameter |
| 701 | to look for. (See ``get_submodule`` for how to specify a |
| 702 | fully-qualified string.) |
| 703 | |
| 704 | Returns: |
| 705 | torch.nn.Parameter: The Parameter referenced by ``target`` |
| 706 | |
| 707 | Raises: |
| 708 | AttributeError: If the target string references an invalid |
| 709 | path or resolves to something that is not an |
| 710 | ``nn.Parameter`` |
| 711 | """ |
| 712 | module_path, _, param_name = target.rpartition(".") |
| 713 | |
| 714 | mod: torch.nn.Module = self.get_submodule(module_path) |
| 715 | |
| 716 | if not hasattr(mod, param_name): |
| 717 | raise AttributeError(mod._get_name() + " has no attribute `" |
| 718 | + param_name + "`") |
| 719 | |
| 720 | param: torch.nn.Parameter = getattr(mod, param_name) |
| 721 | |
| 722 | if not isinstance(param, torch.nn.Parameter): |
| 723 | raise AttributeError("`" + param_name + "` is not an " |
| 724 | "nn.Parameter") |
| 725 | |
| 726 | return param |
| 727 | |
| 728 | def get_buffer(self, target: str) -> "Tensor": |
| 729 | """Return the buffer given by ``target`` if it exists, otherwise throw an error. |