llamalike_from_huggingface_model

llamalike_from_huggingface_model#

penzai.models.transformer.variants.llamalike_common.llamalike_from_huggingface_model(model: Any, upcast_activations_to_float32: bool = False, use_layer_stack: bool = False) model_parts.TransformerLM[source]#

Converts a “llama-like” HuggingFace model to a Penzai model.

This function converts Llama-like models from their HuggingFace implementations to Penzai. It does not do any checks and blindly assumes that the architecture follows the defaults from the Llama model family. You may want to use the model-specific wrappers in variants.llama or variants.mistral instead.

Parameters:
  • model – The HuggingFace model, which is assumed to be similar to the Llama or Mistral architectures. (Not all configuration arguments are checked, so this may end up producing different behavior if given an incompatible configuration.)

  • upcast_activations_to_float32 – Whether to cast activations to float32 when the model runs. This allows analyzing activations at higher precision without consuming additional memory for parameters.

  • use_layer_stack – Whether to use a layer stack for the decoder blocks.

Returns:

A Transformer model containing the loaded parameters, assuming a Llama-like architecture.