forward_pass.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:pdnn 作者: petered 项目源码 文件源码
def quantized_forward_pass_cost_and_output(inputs, weights, scales, biases=None, quantization_method='round',
        hidden_activations='relu', output_activation = 'relu', computation_calc='adds', seed=None):
    """
    Do a forward pass of a discretized network, and return the (pseudo) computational cost and final output.

    :param inputs: A (n_samples, n_dims) array of inputs
    :param weights: A list of (n_dim_in, n_dim_out) arrays of weights
    :param scales: A list of (w[0].shape[0], w[1].shape[0], ...) scales to multiply/divide by before/after the quantization
    :param quantization_method: The method of quantization/discretization: 'round', 'uniform', None, ....
    :param seed: A random seed or number generator
    :return: n_ops, output_activation: Where:
        n_ops is the (scalar) number of commputations required in the forward pass (only striclty true if scale is 'round', .. otherwise it's some kind of surrogate.
        output_activation: A (n_samples, n_dims) array representing the output activations.
    """
    activations = scaled_quantized_forward_pass(inputs= inputs, weights=weights, biases=biases, scales=scales,
        hidden_activations=hidden_activations, output_activations=output_activation, quantization_method=quantization_method, rng=seed)
    spike_activations = activations[1::3]
    n_ops = sparse_nn_flop_count(spike_activations, [w.shape[1] for w in weights], mode=computation_calc) if quantization_method is not None else None
    return n_ops, activations[-1]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号