k1lib.selector module

This module is for selecting a subnetwork so that you can do special things to them. Checkout the tutorial section for a walkthrough. This is exposed automatically with:

from k1lib.imports import *
selector.select # exposed
class k1lib.selector.ModuleSelector(parent: ModuleSelector, name: str, nnModule: torch.nn.Module)[source]

Bases: object

selectedProps: List[str]

Selected properties of this MS

property displayF

Function to display each ModuleSelector’s lines. Default is just:

lambda mS: ", ".join(mS.selectedProps) 
clearProps()[source]
highlight(prop: str)[source]
selected(prop: Optional[str] = None)bool[source]

Whether this ModuleSelector has a specific prop

named_children()Iterator[Tuple[str, k1lib.selector.ModuleSelector]][source]

Get all named direct child

named_modules(prop: Optional[str] = None)Iterator[Tuple[str, k1lib.selector.ModuleSelector]][source]

Get all named child recursively

Parameters

prop – Filter property

children()Iterator[k1lib.selector.ModuleSelector][source]

Get all direct child

modules(prop: Optional[str] = None)Iterator[k1lib.selector.ModuleSelector][source]

Get all child recursively. Optional filter prop

property directParams

Params directly under this module

parameters()Iterator[torch.nn.parameter.Parameter][source]

Get generator of parameters, all depths

property deepestDepth

Deepest depth of the tree. If self doesn’t have any child, then depth is 0

apply(f: Callable[[k1lib.selector.ModuleSelector], None])

Applies a function to self and all child ModuleSelector

copy()
parse(selectors: List[str])

Parses extra selectors. Clears all old selectors, but retain the props

k1lib.selector.filter(selectors: str, defaultProp='all')List[str][source]

Removes all quirkly features allowed by the css language, and outputs nice lines.

Parameters
  • selectors – single css selector string. Statements separated by “\n” or “;”

  • defaultProp – default property, if statement doesn’t have one

k1lib.selector.select(model: torch.nn.Module, selectors: str)k1lib.selector.ModuleSelector[source]

Creates a new ModuleSelector, in sync with a model