class_docstr: Subclass of :class:`MutableModule` supports mutables as initialization parameters.
  
  One important feature of :class:`ParametrizedModule` is that
  it automatically freeze the mutable arguments passed to ``__init__``.
  This is for the convenience as well as compatibility with existing code::
  
      class MyModule(ParametrizedModule):
          def __init__(self, x):
              super().__init__()
              self.t = x   # Will be a fixed number, e.g., 3.
  
      MyModule(nni.choice('choice1', [1, 2, 3]))
  
  Note that the mutable arguments need to be directly posed as arguments to ``__init__``.
  They can't be hidden in a list or dict.
  
  If users want to make a 3rd-party module *parametrized*,
  it's recommended to do the following (taking ``nn.Conv2d`` as an example):
  
      >>> class ParametrizedConv2d(ParametrizedModule, nn.Conv2d, wraps=nn.Conv2d):
      ...     pass
      >>> conv = ParametrizedConv2d(3, nni.choice('out', [8, 16]))
      >>> conv
      >>> conv.out_channels
      8
      >>> conv.args['out_channels']
      Categorical([8, 16], label='out')
      >>> conv.freeze({'out': 16})
      Conv2d(3, 16, kernel_size=(1, 1), stride=(1, 1))
  
  .. tip::
  
      The parametrized version of modules in ``torch.nn`` are already provided in ``nni.nas.nn.pytorch``.
      Every class is prefixed with ``Mutable``.
      For example, :class:`nni.nas.nn.pytorch.MutableConv2d`` is a parametrized version of ``torch.nn.Conv2d``.
  
  Attributes
  ----------
  args
      The arguments used to initialize the module.
      Since :class:`ParametrizedModule` will hijack the init arguments before passing to ``__init__``,
      this is the only recommended way to retrieve the original init arguments back.
  
  Warnings
  --------
  :class:`ParametrizedModule` can be nested.
  It's also possible to put arbitrary mutable modules inside a :class:`ParametrizedModule`.
  But be careful if the inner mutable modules are dependant on the parameters of :class:`ParametrizedModule`,
  because NNI can't handle cases where the mutables are a dynamically changing after initialization.
  For example, the following snippet is WRONG::
  
      class MyModule(ParametrizedModule):
          def __init__(self, x):
              if x == 0:
                  self.mutable = self.add_mutable(nni.choice('a', [1, 2, 3]))
              else:
                  self.mutable = self.add_mutable(nni.choice('b', [4, 5, 6]))
  
      module = MyModule(nni.choice('x', [0, 1]))
class_docstr_tok: ["Subclass","of",":","class",":","`","MutableModule","`","supports","mutables","as","initialization","parameters",".","One","important","feature","of",":","class",":","`","ParametrizedModule","`","is","that","it","automatically","freeze","the","mutable","arguments","passed","to","``","__init__","``",".","This","is","for","the","convenience","as","well","as","compatibility","with","existing","code",":",":","class","MyModule","(","ParametrizedModule",")",":","def","__init__","(","self",",","x",")",":","super","(",")",".__init__","(",")","self.t","=","x","#","Will","be","a","fixed","number",",","e.g.",",","3",".","MyModule","(","nni.choice","(","'choice1","'",",","[","1",",","2",",","3","]",")",")","Note","that","the","mutable","arguments","need","to","be","directly","posed","as","arguments","to","``","__init__","``",".","They","ca","n't","be","hidden","in","a","list","or","dict",".","If","users","want","to","make","a","3rd-party","module","*","parametrized","*",",","it","'s","recommended","to","do","the","following","(","taking","``","nn.Conv2d","``","as","an","example",")",":",">",">",">","class","ParametrizedConv2d","(","ParametrizedModule",",","nn.Conv2d",",","wraps=nn.Conv2d",")",":","...","pass",">",">",">","conv","=","ParametrizedConv2d","(","3",",","nni.choice","(","'out","'",",","[","8",",","16","]",")",")",">",">",">","conv",">",">",">","conv.out_channels","8",">",">",">","conv.args","[","'out_channels","'","]","Categorical","(","[","8",",","16","]",",","label='out","'",")",">",">",">","conv.freeze","(","{","'out","'",":","16","}",")","Conv2d","(","3",",","16",",","kernel_size=","(","1",",","1",")",",","stride=","(","1",",","1",")",")","..","tip",":",":","The","parametrized","version","of","modules","in","``","torch.nn","``","are","already","provided","in","``","nni.nas.nn.pytorch","``",".","Every","class","is","prefixed","with","``","Mutable","``",".","For","example",",",":","class",":","`","nni.nas.nn.pytorch.MutableConv2d","``","is","a","parametrized","version","of","``","torch.nn.Conv2d","``",".","Attributes","--","--","--","--","--","args","The","arguments","used","to","initialize","the","module",".","Since",":","class",":","`","ParametrizedModule","`","will","hijack","the","init","arguments","before","passing","to","``","__init__","``",",","this","is","the","only","recommended","way","to","retrieve","the","original","init","arguments","back",".","Warnings","--","--","--","--",":","class",":","`","ParametrizedModule","`","can","be","nested",".","It","'s","also","possible","to","put","arbitrary","mutable","modules","inside","a",":","class",":","`","ParametrizedModule","`",".","But","be","careful","if","the","inner","mutable","modules","are","dependant","on","the","parameters","of",":","class",":","`","ParametrizedModule","`",",","because","NNI","ca","n't","handle","cases","where","the","mutables","are","a","dynamically","changing","after","initialization",".","For","example",",","the","following","snippet","is","WRONG",":",":","class","MyModule","(","ParametrizedModule",")",":","def","__init__","(","self",",","x",")",":","if","x","==","0",":","self.mutable","=","self.add_mutable","(","nni.choice","(","'","a","'",",","[","1",",","2",",","3","]",")",")","else",":","self.mutable","=","self.add_mutable","(","nni.choice","(","'","b","'",",","[","4",",","5",",","6","]",")",")","module","=","MyModule","(","nni.choice","(","'","x","'",",","[","0",",","1","]",")",")"]
docstr: Freeze the init arguments with the given context, and return the frozen arguments.
code: def freeze_init_arguments(
      sample: Optional[Sample], *args, **kwargs
  ) -> Tuple[tuple, dict]:
      """Freeze the init arguments with the given context, and return the frozen arguments."""
      args_ = tuple(ensure_frozen(arg, sample=sample) for arg in args)
      kwargs_ = {
          kw: ensure_frozen(arg, sample=sample)
          for kw, arg in kwargs.items()
      }
      return args_, kwargs_
  
imports: import copy
  import itertools
  import inspect
  import logging
  from typing import Any, Callable, Type, Iterable, Dict, Tuple, List, Optional, TypeVar
  import torch
  from torch import nn
  from nni.mutable import Mutable, LabeledMutable, Sample, SampleValidationError, ensure_frozen, frozen_context, label_scope, frozen
  from nni.nas.space import BaseModelSpace, current_model, model_context
  from nni.common.serializer import SerializableObject, _formulate_arguments, _copy_class_wrapper_attributes
label_desc: Use image node_id 5 for calling the ParametrizedModule obj's underlying member method code with example usage: obj.freeze_init_arguments(sample) and returns: args_,  kwargs_