transform.quantize_methods.global_quantize

transform.quantize_methods.global_quantize(weights_in: ndarray, weights_rec: ndarray, weights_out: ndarray, threshold: ndarray, threshold_out: ndarray, dash_mem: ndarray, dash_mem_out: ndarray, dash_syn: ndarray, dash_syn_2: ndarray, dash_syn_out: ndarray, bias: ndarray | None = None, bias_out: ndarray | None = None, fuzzy_scaling: bool = False, bits_per_weight: int = 8, bits_per_threshold: int = 16, *_, **__)[source]

Quantize a Xylo model for deployment, using global parameter scaling

The figure below illustrates the groups of weights which are considered for quantization. Under this global method, all weights in the network are considered together when scaling and quantizing weights and thresholds. Input and recurrent weights are considered together as a group; output weights are considered separately when quantizing. Dashes are rounded and cast to integer.

            target
    -------------------
s   -------------------  -
o   -**- -**- -**- -**-  -
u   -**- -**- -**- -**-  -
r   -**- -**- -**- -**-  -
c   -**- -**- -**- -**-  -
e   -**- -**- -**- -**-  -
    -------------------

Examples

>>> specs = xylo.devices.mapper(net.as_graph(), weight_dtype="float", threshold_dtype="float")
>>> specs.update(global_quantize(**specs, fuzzy_scaling = True))
>>> xylo.devices.XyloSim.from_specifications(specs)
Parameters:
  • weights_in (np.ndarray) – Input weight matrix

  • weights_rec (np.ndarray) – Recurrent weight matrix

  • weights_out (np.ndarray) – Output weight matrix

  • threshold (np.ndarray) – Firing threshold for hidden neurons

  • threshold_out (np.ndarray) – Firing threshold for output neurons

  • dash_mem (np.ndarray) – Dash for membrane potential of hidden neurons

  • dash_mem_out (np.ndarray) – Dash for membrane potential of output neurons

  • dash_syn (np.ndarray) – Dash for synaptic current of hidden neurons

  • dash_syn_2 (np.ndarray) – Dash for second synaptic current of hidden neurons

  • dash_syn_out (np.ndarray) – Dash for synaptic current of output neurons

  • bias (np.ndarray) – Bias for hidden neurons

  • bias_out (np.ndarray) – Bias for output neurons

  • fuzzy_scaling (bool) – If True, scale and clip weights to 2*std dev. If False (default), scale and clip to maximum absolute weight.

  • bits_per_weight (int) – Number of bits per integer signed weight. Default: 8

  • bits_per_threshold (int) – Number of bits per integer signed threshold. Default: 16

Returns:

model_quan which can be used to update a Xylo specification dictionary

Return type:

dict