Model-based jailbreak detection cannot load `Snowflake/snowflake-arctic-embed-m-long` with transformers 5.x
Version: nemoguardrails 0.24.1, transformers 5.18.0, torch 2.14.1 (CPU), Python 3.12.3, Windows 11. Also reproduced online (not only offline).
What happens. With the jailbreak detection model input rail configured for in-process
detection (EMBEDDING_CLASSIFIER_PATH set to a directory holding snowflake.onnx from
nvidia/NemoGuard-JailbreakDetect), the first request fails while loading the embedding model:
File ".../modeling_hf_nomic_bert.py", line 345, in from_pretrained
state_dict = state_dict_from_pretrained(model_name, safe_serialization=kwargs.get("safe_serialization", False))
File ".../modeling_hf_nomic_bert.py", line 73, in state_dict_from_pretrained
raise EnvironmentError(f"Model name {model_name} was not found.")
OSError: Model name Snowflake/snowflake-arctic-embed-m-long was not found.
The custom loader in the Snowflake repository (revision 92d97331) looks for pytorch_model.bin
on the Hub; the repository only ships model.safetensors, and use_safetensors=True passed by
SnowflakeEmbed is not the kwarg the custom code reads (safe_serialization). If the weights are
made available locally so that loading proceeds, the forward pass then fails on transformers 5:
AttributeError: 'NomicBertModel' object has no attribute 'get_extended_attention_mask'
library/jailbreak_detection/requirements.txt pins transformers>=5.3.0, so the documented
server setup hits this. The same code works with transformers 4.57.6 when
SNOWFLAKE_MODEL_ID points at a local snapshot directory.
Effect. The rail cannot run in-process; every request through it ends with "I'm sorry, an internal error has occurred." (fails closed).
Steps.
pip install nemoguardrails==0.24.1 "transformers>=5.3" torch langchain-openai
set EMBEDDING_CLASSIFIER_PATH=<dir with snowflake.onnx>
# config.yml: rails.input.flows: [jailbreak detection model]; rails.config.jailbreak_detection.embedding: snowflake/snowflake-arctic-embed-m-long
python -c "from nemoguardrails.library.jailbreak_detection.model_based.models import JailbreakClassifier; JailbreakClassifier('<dir>/snowflake.onnx')"
Suggested fix. Either load the embedding model without trust_remote_code (the architecture
is available upstream as NomicBert in recent transformers), pass safe_serialization=True through
to the custom loader and pin a Snowflake revision that supports transformers 5, or pin
transformers<5 for this rail until the upstream model code is updated.
Opened #2441 with the fix: the embedding model is loaded without remote code (the architecture is native to transformers as NomicBert), verified on transformers 5.19 in a clean container, with a regression test.