Skip to content

huggingface

A module for utilities for Hugging Face transformers.

Functions:

Name Description
get_base_model_decoder

Get the base model decoder from a Hugging Face model.

get_base_model_decoder

get_base_model_decoder(model: PreTrainedModel) -> <class 'transformers.modeling_utils.PreTrainedModel'>

Get the base model decoder from a Hugging Face model.

Typically, Hugging Face *ForCausalLM models wrap a base model that contains the actual architecture. This model can be accessed via the get_decoder method, but some models, like Llama4ForCausalLM do not implement this method correctly in Transformers v5.0.0. This utility function attempts to retrieve the base model decoder in a more robust way.

Parameters:

Name Type Description Default

model

PreTrainedModel

The Hugging Face model.

required

Returns:

Type Description
<class 'transformers.modeling_utils.PreTrainedModel'>

The base model decoder.

Raises:

Type Description
AttributeError

If the base model decoder cannot be found.