Buckets:
Model Weight Transformation Specs
The transformation specs API defines how model weights are transformed between the original Transformers implementation and the custom implementation optimized for Neuron devices. This enables automatic weight conversion during model loading and checkpoint consolidation.
Base Classes
ModelWeightTransformationSpec[[optimum.neuron.models.training.ModelWeightTransformationSpec]]
class optimum.neuron.models.training.ModelWeightTransformationSpecoptimum.neuron.models.training.ModelWeightTransformationSpec
This class defines the interface for transforming model weights between the original Transformers implementation and the custom implementation for Neuron.
adapt_peft_configoptimum.neuron.models.training.ModelWeightTransformationSpec.adapt_peft_config
Adapts the PEFT config to match the custom modeling implementation.
adapt_state_dictoptimum.neuron.models.training.ModelWeightTransformationSpec.adapt_state_dict
Transforms the state dict from the original Transformers model to match the custom modeling implementation.
get_relevant_parameter_namesoptimum.neuron.models.training.ModelWeightTransformationSpec.get_relevant_parameter_names
Returns the set of parameter names that this spec would affect.
guess_peft_typeoptimum.neuron.models.training.ModelWeightTransformationSpec.guess_peft_type
Guesses the PEFT type of the module associated to the spec.
to_original_peft_configoptimum.neuron.models.training.ModelWeightTransformationSpec.to_original_peft_config
Restores the PEFT config to the original one that matches the original Transformers implementation.
to_original_weightsoptimum.neuron.models.training.ModelWeightTransformationSpec.to_original_weights
- parameters_metadata (dict[str, dict[str, Any]]) -- Metadata about the parameters in the original model.0tuple[dict[str, torch.Tensor], list[str]]A tuple containing the transformed weights and a list of the names of the parameters to remove from the final state dict.
Produces the weights associated to this transformation spec from the custom model to match the original Transformers weights.
ModelWeightTransformationSpecs[[optimum.neuron.models.training.ModelWeightTransformationSpecs]]
class optimum.neuron.models.training.ModelWeightTransformationSpecsoptimum.neuron.models.training.ModelWeightTransformationSpecs
Defines a list of transformation specs for a given module of the model.
CustomModule[[optimum.neuron.models.training.CustomModule]]
class optimum.neuron.models.training.CustomModuleoptimum.neuron.models.training.CustomModule
This class is used to mark a module as a custom module. It is used to identify the modules that contain weights that need to transformed when loading and saving the model.
Transformation Specifications
FusedLinearsSpec[[optimum.neuron.models.training.FusedLinearsSpec]]
class optimum.neuron.models.training.FusedLinearsSpecoptimum.neuron.models.training.FusedLinearsSpec
Represents a transformation where multiple linear layers are fused into a single linear layer. It can handle the case where the fused linear layer is sharded across multiple tensor parallel ranks.
GQAQKVColumnParallelLinearSpec[[optimum.neuron.models.training.GQAQKVColumnParallelLinearSpec]]
class optimum.neuron.models.training.GQAQKVColumnParallelLinearSpecoptimum.neuron.models.training.GQAQKVColumnParallelLinearSpec
Represents the transformation of separate query, key, and value projections into a single GQAQKVColumnParalleLinear projection.
compute_query_indices_for_rankoptimum.neuron.models.training.GQAQKVColumnParallelLinearSpec.compute_query_indices_for_rank
Computes the permutation for the query weight for a given TP rank.
create_kv_proj_local_weight_from_regular_weightoptimum.neuron.models.training.GQAQKVColumnParallelLinearSpec.create_kv_proj_local_weight_from_regular_weight
Creates the local version of the key or value projections weight for the given TP rank.
create_query_or_output_projection_local_weight_from_regular_weightoptimum.neuron.models.training.GQAQKVColumnParallelLinearSpec.create_query_or_output_projection_local_weight_from_regular_weight
Creates the local version of the query or output projections weight for the given TP rank.
Utility Functions
Weight Creation Functions[[optimum.neuron.models.training.transformations_utils.create_local_weight_with_padding]]
optimum.neuron.models.training.transformations_utils.create_local_weight_with_paddingoptimum.neuron.models.training.transformations_utils.create_local_weight_with_padding
Shards a tensor along a given axis and return a slice corresponding to the rank. This will round up the layer to the next multiple if there is need to pad the tensor.
optimum.neuron.models.training.transformations_utils.create_local_fused_weightoptimum.neuron.models.training.transformations_utils.create_local_fused_weight
Shards individual weights across the tensor parallel ranks and fuses them into a single weight.
Model-level Functions[[optimum.neuron.models.training.specialize_transformation_specs_for_model]]
optimum.neuron.models.training.specialize_transformation_specs_for_modeloptimum.neuron.models.training.specialize_transformation_specs_for_model
optimum.neuron.models.training.adapt_peft_config_for_modeloptimum.neuron.models.training.adapt_peft_config_for_model
optimum.neuron.models.training.to_original_peft_config_for_modeloptimum.neuron.models.training.to_original_peft_config_for_model
State Dict Functions[[optimum.neuron.models.training.adapt_state_dict]]
optimum.neuron.models.training.adapt_state_dictoptimum.neuron.models.training.adapt_state_dict
Transforms the state dict from the original Transformers model to match the custom modeling implementation.
optimum.neuron.models.training.to_original_weightsoptimum.neuron.models.training.to_original_weights
Consolidates the sharded state dicts produced by saving the custom model into a single state dict that matches the original Transformers model weights.
Metadata Functions[[optimum.neuron.models.training.create_parameter_metadata]]
optimum.neuron.models.training.create_parameter_metadataoptimum.neuron.models.training.create_parameter_metadata
Creates the metadata to be saved with the model weights to be able to reconstruct the original weights when consolidating the sharded state dicts.
optimum.neuron.models.training.transformations_utils.get_tensor_model_parallel_attributesoptimum.neuron.models.training.transformations_utils.get_tensor_model_parallel_attributes
Returns the tensor model parallel attributes of a tensor.
Helper Functions[[optimum.neuron.models.training.transformations_utils.remove_adapter_name]]
optimum.neuron.models.training.transformations_utils.remove_adapter_nameoptimum.neuron.models.training.transformations_utils.remove_adapter_name
optimum.neuron.models.training.transformations_utils.is_base_layeroptimum.neuron.models.training.transformations_utils.is_base_layer
optimum.neuron.models.training.transformations_utils.get_adapter_nameoptimum.neuron.models.training.transformations_utils.get_adapter_name
Xet Storage Details
- Size:
- 20.1 kB
- Xet hash:
- 5a1eb8fab70e2a151513aabe2b834c8ac52e7cad4e738e15c12705f73adb5d97
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.