reset_excluded_layers

paddle.static.sparsity. reset_excluded_layers ( main_program=None ) [source]

Reset exculded layers setting corresponding to main_program. If main_program is None, then all configurations of excluded_layers would be cleaned.

Parameters
  • main_program (Program, optional) – Program with model definition and its parameters.

  • Examples

  • code-block: (.) –

    python: import paddle from paddle.static import sparsity

    paddle.enable_static()

    main_program = paddle.static.Program() startup_program = paddle.static.Program()

    with paddle.static.program_guard(main_program, startup_program):

    input_data = paddle.static.data(name=’data’, shape=[None, 128]) label = paddle.static.data(name=’label’, shape=[None, 10]) hidden = paddle.static.nn.fc(x=input_data, num_flatten_dims=-1, size=32, activation=None, name=”my_first_fc”) hidden = paddle.static.nn.fc(x=hidden, num_flatten_dims=-1, size=32, activation=None, name=”my_second_fc”) prob = paddle.static.nn.fc(x=hidden, num_flatten_dims=-1, size=10, activation=None) loss = paddle.mean(paddle.nn.functional.square_error_cost(prob, label))

    # Setup exluded layers out from ASP workflow. # Please note, excluded_layers must be set before calling optimizer.minimize(). sparsity.set_excluded_layers(main_program, [“my_second_fc”]) # Now the weights of “my_second_fc” would not be included in Automatic SParsity’s workflow.

    # Reset excluded_layers, all FC layers would be included into Automatic SParsity’s workflow. # Please note, reset_excluded_layers also must be called before calling optimizer.minimize(). sparsity.reset_excluded_layers(main_program)