# Why get\_parameter\_names()?

**URL:** <https://discuss.huggingface.co/t/why-get-parameter-names/76475>\
**Category:** Beginners\
**Created:** [March 8, 2024, 3:10am UTC](https://discuss.huggingface.co/t/why-get-parameter-names/76475 "2024-03-08T03:10:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mst272](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@mst272](https://discuss.huggingface.co/u/mst272)\
**Post date:** [March 8, 2024, 3:10am UTC](https://discuss.huggingface.co/t/why-get-parameter-names/76475/1 "2024-03-08T03:10:37Z")

</div>

in transformers/trainer\_pt\_utils.py, get\_parameter\_names() is as follow:

```auto
def get_parameter_names(model, forbidden_layer_types):
    """
    Returns the names of the model parameters that are not inside a forbidden layer.
    """
    result = []
    for name, child in model.named_children():
        result += [
            f"{name}.{n}"
            for n in get_parameter_names(child, forbidden_layer_types)
            if not isinstance(child, tuple(forbidden_layer_types))
        ]
    # Add model specific parameters (defined with nn.Parameter) since they are not in any child.
    result += list(model._parameters.keys())
    return result

```

If the linear layer bias of my model is set to False.I use the following code to print the model structure, and the output result is that there is no bias layer：

```auto
for k,v in model.named_parameters():
    print(k)

# output：
base_model.model.model.embed_tokens.weight
base_model.model.model.layers.0.self_attn.q_proj.base_layer.weight
base_model.model.model.layers.0.self_attn.q_proj.lora_A.default.weight
base_model.model.model.layers.0.self_attn.q_proj.lora_B.default.weight
base_model.model.model.layers.0.self_attn.k_proj.base_layer.weight

```

but when i use get\_parameter\_names(), the output is like this:

```auto
'base_model.model.model.embed_tokens.weight',
 'base_model.model.model.layers.0.self_attn.q_proj.base_layer.weight',
 'base_model.model.model.layers.0.self_attn.q_proj.base_layer.bias',
 'base_model.model.model.layers.0.self_attn.q_proj.lora_A.default.weight',
 'base_model.model.model.layers.0.self_attn.q_proj.lora_A.default.bias',
 'base_model.model.model.layers.0.self_attn.q_proj.lora_B.default.weight',

```

I want to know why it is necessary to use` "for name, child in model.named_children():"` to implement the get\_parameter\_names() function. Wouldn’t it be better to use` for name, param in model.named_parameters()`？
