Feature Extraction
Transformers
TensorBoard
Safetensors
English
captionbert_structured_rotary
sentence-similarity
consensus-distillation
rotary-embeddings
custom_code
Instructions to use AbstractPhil/captionbert-8192-rotary with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AbstractPhil/captionbert-8192-rotary with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="AbstractPhil/captionbert-8192-rotary", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("AbstractPhil/captionbert-8192-rotary", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Preserve trained-binding serving source for latest Colab parity
Browse files
campaigns/structured-20261106/validation/binding-serving-colab/20261106T183200Z/configuration_captionbert.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Self-contained configuration shipped beside the safetensors AutoModel."""
|
| 2 |
+
from transformers import PretrainedConfig
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class CaptionBertConfig(PretrainedConfig):
|
| 6 |
+
model_type = "captionbert_structured_rotary"
|
| 7 |
+
|
| 8 |
+
def __init__(self, vocab_size=30522, hidden_size=512, num_hidden_layers=12,
|
| 9 |
+
num_attention_heads=16, intermediate_size=2048, output_dim=768,
|
| 10 |
+
max_position_embeddings=8192, hidden_dropout_prob=0.1,
|
| 11 |
+
rotary_mode="key_all", lookup_layer=3, lookup_head=0,
|
| 12 |
+
pointer_weight=0.1, pointer_positions="all", key_rho=2.18,
|
| 13 |
+
use_value_addresses=True, gradient_checkpointing=True,
|
| 14 |
+
continuation_ids=None, punctuation_ids=None, special_ids=None,
|
| 15 |
+
phase_seed=1662197431, pad_token_id=0, **kwargs):
|
| 16 |
+
super().__init__(pad_token_id=pad_token_id, **kwargs)
|
| 17 |
+
self.vocab_size = int(vocab_size)
|
| 18 |
+
self.hidden_size = int(hidden_size)
|
| 19 |
+
self.num_hidden_layers = int(num_hidden_layers)
|
| 20 |
+
self.num_attention_heads = int(num_attention_heads)
|
| 21 |
+
self.intermediate_size = int(intermediate_size)
|
| 22 |
+
self.output_dim = int(output_dim)
|
| 23 |
+
self.max_position_embeddings = int(max_position_embeddings)
|
| 24 |
+
self.hidden_dropout_prob = float(hidden_dropout_prob)
|
| 25 |
+
self.rotary_mode = rotary_mode
|
| 26 |
+
self.lookup_layer, self.lookup_head = int(lookup_layer), int(lookup_head)
|
| 27 |
+
self.pointer_weight = float(pointer_weight)
|
| 28 |
+
self.pointer_positions = pointer_positions
|
| 29 |
+
self.key_rho = float(key_rho)
|
| 30 |
+
self.use_value_addresses = bool(use_value_addresses)
|
| 31 |
+
self.gradient_checkpointing = bool(gradient_checkpointing)
|
| 32 |
+
self.continuation_ids = list(continuation_ids or [])
|
| 33 |
+
self.punctuation_ids = list(punctuation_ids if punctuation_ids is not None else [1012, 999, 1029])
|
| 34 |
+
self.special_ids = list(special_ids if special_ids is not None else [0, 100, 101, 102, 103])
|
| 35 |
+
self.phase_seed = int(phase_seed)
|
| 36 |
+
if rotary_mode not in ("rope", "ntk", "hierarchical", "key_end", "key_all"):
|
| 37 |
+
raise ValueError("Unknown rotary_mode")
|
| 38 |
+
if hidden_size % num_attention_heads or (hidden_size // num_attention_heads) % 2:
|
| 39 |
+
raise ValueError("Attention heads must contain an even number of dimensions")
|
| 40 |
+
if rotary_mode in ("hierarchical", "key_end", "key_all") and hidden_size // num_attention_heads != 32:
|
| 41 |
+
raise ValueError("The source-faithful 8x3 band requires 32-dimensional heads")
|
| 42 |
+
if min(vocab_size, hidden_size, num_hidden_layers, intermediate_size, output_dim) < 1:
|
| 43 |
+
raise ValueError("Dimensions must be positive")
|
| 44 |
+
if not 0 <= lookup_layer < num_hidden_layers or not 0 <= lookup_head < num_attention_heads:
|
| 45 |
+
raise ValueError("Lookup layer/head is outside the model")
|
| 46 |
+
if pointer_positions not in ("end", "all") or pointer_weight < 0 or key_rho < 0:
|
| 47 |
+
raise ValueError("Invalid pointer/norm configuration")
|
| 48 |
+
|