pytorch_pfn_extras.handler.CodeBlock#

class pytorch_pfn_extras.handler.CodeBlock(func, optimizers, backprop, backprop_from, backprop_to, state, runtime)#

Bases: object

Class that is used to specify and apply actions to a callable.

CodeBlocks are used in Logic classes to write device agnostic codes, as the device runtime is in charge of doing the execution of the module with the actions requested from the codeblock

Parameters:
  • func (Callable) – The function to be operated according to the specified options.

  • optimizer – The Optimizer that will be used for parameter update.

  • backprop (bool) – Flag to specify if gradients are to be calculated.

  • backprop_from (Optional[str]) – Select a single output from the block execution to perform the gradient calculation.

  • backprop_to (Optional[Set[str]]) – Name of the values where backpropagation will be stopped.

  • state (Dict[str, Any]) – Data that can be used during the CodeBlock execution.

  • optimizers (List[Optimizer]) –

  • runtime (Any) –

Methods

__init__(func, optimizers, backprop, ...)

load_state_dict(state)

state_dict()

Attributes

func

optimizers

backprop

backprop_from

backprop_to

state

runtime

__call__(inputs)#

Call self as a function.

Parameters:

inputs (Any) –

Return type:

Any

__init__(func, optimizers, backprop, backprop_from, backprop_to, state, runtime)#
Parameters:
  • func (Callable) –

  • optimizers (List[Optimizer]) –

  • backprop (bool) –

  • backprop_from (Optional[str]) –

  • backprop_to (Optional[Set[str]]) –

  • state (Dict[str, Any]) –

  • runtime (Any) –

Return type:

None

backprop: bool#
backprop_from: Optional[str]#
backprop_to: Optional[Set[str]]#
func: Callable#
load_state_dict(state)#
Parameters:

state (Dict[str, Any]) –

Return type:

None

optimizers: List[Optimizer]#
runtime: Any#
state: Dict[str, Any]#
state_dict()#
Return type:

Dict[str, Any]