# Remove layer in pretrained model

**URL:** <https://discuss.huggingface.co/t/remove-layer-in-pretrained-model/38609>\
**Category:** Beginners\
**Created:** [May 4, 2023, 1:29am UTC](https://discuss.huggingface.co/t/remove-layer-in-pretrained-model/38609 "2023-05-04T01:29:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![azhang0](https://avatars.discourse-cdn.com/v4/letter/a/a5b964/32.png) [@azhang0](https://discuss.huggingface.co/u/azhang0)\
**Post date:** [May 4, 2023, 1:29am UTC](https://discuss.huggingface.co/t/remove-layer-in-pretrained-model/38609/1 "2023-05-04T01:29:20Z")

</div>

I’m new to ML, I’m trying to perform an ablation study. Is there a concise way to access and remove layers from a pretrained model? Specifically, I’m working on this code:

```auto
pretrained_model_name = "nvidia/mit-b0"
model = AutoModelForSemanticSegmentation.from_pretrained(
    pretrained_model_name, id2label=id2label, label2id=label2id
)

# to-do: something like "model.remove_layers(-1)"

```

I know there’s model.config, but it doesn’t seem to have what I’m looking for. Any tips? Thanks!

---

<div class="post-metadata">

**Author:** ![snaky-rigz](https://avatars.discourse-cdn.com/v4/letter/s/65b543/32.png) [@snaky-rigz](https://discuss.huggingface.co/u/snaky-rigz)\
**Post date:** [October 14, 2025, 9:50am UTC](https://discuss.huggingface.co/t/remove-layer-in-pretrained-model/38609/2 "2025-10-14T09:50:37Z")

</div>

This worked for me 🙂

> model = AutoModelForSequenceClassification.from\_pretrained(“BAAI/bge-small-en-v1.5”, num\_labels=3, id2label=id2label, label2id=label2id)
> 
> model.base\_model.encoder.layer = model.base\_model.encoder.layer[:-1]
