Rorical commited on
Commit
5683b4a
·
verified ·
1 Parent(s): 13d1f86

Upload configuration_logos.py

Browse files
Files changed (1) hide show
  1. configuration_logos.py +114 -0
configuration_logos.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """HuggingFace configuration for Logos."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ import importlib
7
+ from pathlib import Path
8
+ from typing import Any, Dict
9
+
10
+ from transformers import PretrainedConfig
11
+
12
+ _MODULE_DIR = Path(__file__).resolve().parent
13
+ if str(_MODULE_DIR) not in sys.path:
14
+ sys.path.insert(0, str(_MODULE_DIR))
15
+
16
+
17
+ _NATIVE_DEFAULTS: Dict[str, Any] = {
18
+ "vocab_size": 32000,
19
+ "d_model": 512,
20
+ "max_seq_len": 2048,
21
+ "num_layers": 8,
22
+ "num_heads": 8,
23
+ "norm_eps": 1e-6,
24
+ "d_ff": 1364,
25
+ "use_moe": True,
26
+ "num_shared_experts": 2,
27
+ "num_sparse_experts": 64,
28
+ "top_k": 6,
29
+ "expert_d_ff": 256,
30
+ "bias_update_rate": 0.01,
31
+ "capacity_factor": 2.0,
32
+ "router_logit_noise_std": 0.1,
33
+ "router_logit_noise_decay_steps": 2000,
34
+ "router_init_std": 0.002,
35
+ "router_bias_error_clip": 1.0,
36
+ "router_bias_clip": 1.0,
37
+ "moe_aux_loss_weight": 1e-3,
38
+ "moe_aux_loss_decay_steps": 2000,
39
+ "lm_head_chunk_size": 0,
40
+ "moe_diversity_factor": 0.0,
41
+ "rope_base": 10000.0,
42
+ "qk_norm": True,
43
+ "partial_rope_dim": None,
44
+ "attention_sink": True,
45
+ "block_residual_isolate_softmax": False,
46
+ "head_dim": 64,
47
+ "conv_size": 4,
48
+ "chunk_size": 64,
49
+ "A_init_range": (1, 16),
50
+ "expand": 2,
51
+ "swa_window": 256,
52
+ "swa_every": 4,
53
+ "swa_offset": 3,
54
+ "csa_compression": 4,
55
+ "csa_top_k": 1024,
56
+ "csa_indexer_heads": 4,
57
+ "csa_indexer_dim": 32,
58
+ "csa_indexer_loss_weight": 1.0,
59
+ "hca_compression": 128,
60
+ "compressed_query_dim": None,
61
+ "compressed_head_dim": None,
62
+ "compressed_rope": False,
63
+ "indexer_rope": False,
64
+ "attn_pattern": None,
65
+ "num_entry_layers": 2,
66
+ "num_body_layers": 4,
67
+ "num_exit_layers": 2,
68
+ "num_loops": 4,
69
+ "entry_attn_pattern": None,
70
+ "body_attn_pattern": None,
71
+ "exit_attn_pattern": None,
72
+ "entry_top_k": None,
73
+ "exit_top_k": None,
74
+ "gradient_checkpointing": False,
75
+ "ckpt_granularity": "per-block",
76
+ }
77
+
78
+
79
+ class LogosConfig(PretrainedConfig):
80
+ model_type = "logos"
81
+ keys_to_ignore_at_inference = ["past_key_values"]
82
+
83
+ def __init__(self, **kwargs: Any):
84
+ native_values: Dict[str, Any] = {}
85
+ for name, default in _NATIVE_DEFAULTS.items():
86
+ native_values[name] = kwargs.pop(name, default)
87
+
88
+ tokenizer_encoding = kwargs.pop("tokenizer_encoding", "cl100k_base")
89
+ kwargs.setdefault("tie_word_embeddings", True)
90
+ super().__init__(**kwargs)
91
+
92
+ for name, value in native_values.items():
93
+ setattr(self, name, value)
94
+ self.tokenizer_encoding = tokenizer_encoding
95
+ self.architectures = ["LogosForCausalLM"]
96
+ self.auto_map = {
97
+ "AutoConfig": "configuration_logos.LogosConfig",
98
+ "AutoModelForCausalLM": "modeling_logos.LogosForCausalLM",
99
+ "AutoTokenizer": ["tokenization_logos.LogosTokenizer", None],
100
+ }
101
+
102
+ def to_native_config(self):
103
+ model_dir = getattr(self, "_name_or_path", None) or getattr(self, "name_or_path", None)
104
+ if model_dir:
105
+ model_path = Path(str(model_dir)).resolve()
106
+ if model_path.exists() and str(model_path) not in sys.path:
107
+ sys.path.insert(0, str(model_path))
108
+ NativeLogosConfig = importlib.import_module("models.logos").LogosConfig
109
+
110
+ data = {name: getattr(self, name) for name in _NATIVE_DEFAULTS}
111
+ return NativeLogosConfig(**data)
112
+
113
+
114
+ __all__ = ["LogosConfig"]