Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions transformer_lens/conversion_utils/param_processing_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ def _resolve_key(self, current_key: str, template_key: str) -> str:
def convert(self, state_dict: Dict[str, torch.Tensor], current_key: str) -> torch.Tensor:
"""Convert a parameter in the state dict.

Fetches tensor from source_key (or current_key if not specified),
applies conversion, and stores result at current_key.
Fetches tensor from source_key (or current_key if not specified)
and applies the conversion.

Args:
state_dict: The state dictionary to modify
current_key: The key where the converted tensor should be stored
state_dict: The state dictionary to read from
current_key: The key of the parameter being converted

Returns:
Modified state dictionary
The converted tensor
"""
# Determine which key to fetch from
fetch_key = current_key
Expand All @@ -73,17 +73,13 @@ def convert(self, state_dict: Dict[str, torch.Tensor], current_key: str) -> torc
return self.tensor_conversion.convert(tensor, state_dict)

def revert(self, tensor: torch.Tensor) -> torch.Tensor:
"""Revert a parameter conversion in the state dict.

Fetches tensor from current_key, applies reversion,
and stores result back at current_key.
"""Revert a parameter conversion.

Args:
state_dict: The state dictionary to modify
current_key: The key of the tensor to revert
tensor: The converted tensor to revert

Returns:
Modified state dictionary
The reverted tensor
"""
# Apply reversion (handles None gracefully)
return self.tensor_conversion.revert(tensor)
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def split_qkv_matrix(
) -> tuple[torch.nn.Linear, torch.nn.Linear, torch.nn.Linear]:
"""Split the QKV matrix into separate linear transformations.
Args:
attention_component: The original attention layer component
original_attention_component: The original attention layer component
Returns:
Tuple of nn.Linear modules for Q, K, and V transformations
"""
Expand Down
6 changes: 3 additions & 3 deletions transformer_lens/tools/training.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ class TrainConfig:
lr (float): Learning rate to use for training
seed (int): Random seed to use for training
momentum (float): Momentum to use for training
max_grad_norm (float, *optional*): Maximum gradient norm to use for
max_grad_norm (float, *optional*): Maximum gradient norm to clip gradients to
weight_decay (float, *optional*): Weight decay to use for training
optimizer_name (str): The name of the optimizer to use
device (str or torch.device, *optional*): Device to use for training
warmup_steps (int, *optional*): Number of warmup steps to use for training
save_every (int, *optional*): After how many batches should a checkpoint be saved
save_dir, (str, *optional*): Where to save checkpoints
save_dir (str, *optional*): Where to save checkpoints
wandb (bool): Whether to use Weights and Biases for logging
wandb_project (str, *optional*): Name of the Weights and Biases project to use
wandb_project_name (str, *optional*): Name of the Weights and Biases project to use
print_every (int, *optional*): Print the loss every n steps
max_steps (int, *optional*): Terminate the epoch after this many steps. Used for debugging.
"""
Expand Down
Loading