MCPcopy Create free account
hub / github.com/eric-mitchell/direct-preference-optimization / get_block_class_from_model

Function get_block_class_from_model

utils.py:120–125  ·  view source on GitHub ↗

Get the class of a block from a model, using the block's class name.

(model: torch.nn.Module, block_class_name: str)

Source from the content-addressed store, hash-verified

118
119
120def get_block_class_from_model(model: torch.nn.Module, block_class_name: str) -> torch.nn.Module:
121 """Get the class of a block from a model, using the block's class name."""
122 for module in model.modules():
123 if module.__class__.__name__ == block_class_name:
124 return module.__class__
125 raise ValueError(f"Could not find block class {block_class_name} in model {model}")
126
127
128def get_block_class_from_model_class_and_block_name(model_class: Type, block_class_name: str) -> Type:

Callers 1

__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected