core/nn/bert_hf_loader library

Loads HuggingFace BERT-style safetensors (bert-base, MiniLM, sentence-transformers/all-MiniLM-, all-mpnet-) into a BertModel. Pooler tensors (pooler.dense.*), position_ids and buffers are ignored — sentence-transformer models don't use the CLS pooler.

HF key conventions handled here:

  • embeddings.word_embeddings.weight V, D
  • embeddings.position_embeddings.weight maxPos, D
  • embeddings.token_type_embeddings.weight typeVocab, D — collapsed to a [1, D] bias (row 0 only).
  • embeddings.LayerNorm.{weight,bias} D
  • encoder.layer.i.attention.self.{query,key,value}.{weight,bias} — weight [D, D] sliced row-wise into 12 per-head chunks [headDim, D]; bias [D] sliced into [headDim] per head.
  • encoder.layer.i.attention.output.dense.{weight,bias}
  • encoder.layer.i.attention.output.LayerNorm.{weight,bias}
  • encoder.layer.i.intermediate.dense.{weight,bias}
  • encoder.layer.i.output.dense.{weight,bias}
  • encoder.layer.i.output.LayerNorm.{weight,bias}