[Misc] Replace assert with proper exceptions for security and validation in pooling (#43286)
Signed-off-by: Taneem Ibrahim <taneem.ibrahim@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
Nick Hill
parent
d3d1cf6972
commit
b3c7ffcab8
@@ -49,10 +49,11 @@ def get_act_fn(
|
||||
function_name = config.sbert_ce_default_activation_function
|
||||
|
||||
if function_name is not None:
|
||||
assert function_name.startswith("torch.nn.modules."), (
|
||||
"Loading of activation functions is restricted to "
|
||||
"torch.nn.modules for security reasons"
|
||||
)
|
||||
if not function_name.startswith("torch.nn.modules."):
|
||||
raise ValueError(
|
||||
"Loading of activation functions is restricted to "
|
||||
"torch.nn.modules for security reasons"
|
||||
)
|
||||
fn = resolve_obj_by_qualname(function_name)()
|
||||
return PoolerActivation.wraps(fn)
|
||||
|
||||
@@ -67,7 +68,8 @@ def resolve_classifier_act_fn(
|
||||
if act_fn is None:
|
||||
return get_act_fn(model_config.hf_config, static_num_labels)
|
||||
|
||||
assert callable(act_fn)
|
||||
if not callable(act_fn):
|
||||
raise TypeError(f"Expected a callable activation function, got {type(act_fn)}")
|
||||
return act_fn
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user