MCPcopy Create free account
hub / github.com/apple/ml-pointersect / StackedModulatedSubspace

Class StackedModulatedSubspace

cdslib/core/nn/modules/subspace.py:315–531  ·  view source on GitHub ↗

Convenient helper nn.Module to create a stack of modulated subspace layers.

Source from the content-addressed store, hash-verified

313
314
315class StackedModulatedSubspace(nn.Module):
316 """
317 Convenient helper nn.Module to create a stack of modulated subspace layers.
318 """
319
320 def __init__(
321 self,
322 in_features: int,
323 out_features: int,
324 layer_configs: T.Sequence[T.Dict[str, T.Any]],
325 ):
326 r"""Construct multiple stacked modulated subspace layers
327 sandwiched between nonlinearity.
328
329 Args:
330 in_features (int):
331 number of input channels
332 out_features (int):
333 number of output channels in the output system
334 layer_configs (list of T.Dict[str, T.Any]):
335 a list of dict (one for each layer) containing the parameters
336 to :py:class:`ModulatedSubspace`
337 and parameters for nonlinearity, and dropout:
338
339 - out_features (int, required):
340 output feature dimension
341 - style_features (int, required):
342 style feature dimension
343 - bias (bool):
344 whether to learn bias :math:`b`. Default: `True`.
345 - fixed_bias (float):
346 a fixed bias b0 added after :math:`Wx + b + b0`. Default: `0`.
347 - input_bias (bool):
348 whether to learn x0. Default: `True`.
349 - fixed_input_bias (float):
350 a fixed bias x1 added after x0. Default: `0`.
351 - lr_multiplier (float):
352 a factor controls the learning rate of the layer. Default: `1`.
353 - demodulate (bool):
354 whether to normalize the row of W. Default: `True`.
355 - normalize_basis (bool):
356 whether to normalize the basis to have unit l2 norm. Default: `True`.
357 - orthogonalize_basis (bool):
358 whether to orthogonalize the basis. Default: `False`.
359 (recommended: False)
360 - dropout (float):
361 the dropout rate. Default: `0`.
362 - nonlinearity (str):
363 ``'none'``, ``'leaky_relu'``, ``'relu'``, ``'tanh'``,
364 ``'sigmoid'``, ``'silu'``. Default: ``'relu'``.
365
366 """
367 super().__init__()
368 self.in_features = in_features
369 self.out_features = out_features
370 self.layer_configs = layer_configs
371 self.num_layers = len(self.layer_configs)
372 assert self.out_features == self.layer_configs[-1]["out_features"]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected