mrinaldi commited on
Commit
b7c976d
·
verified ·
1 Parent(s): 5dd39aa

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. README.md +28 -0
  2. checkpoint.ckpt +3 -0
  3. config.json +117 -0
  4. matformer_config.json +68 -0
  5. modeling_matformer.py +47 -0
README.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - matformer
4
+ - custom-model
5
+ library_name: transformers
6
+ ---
7
+
8
+ # Matformer Model
9
+
10
+ Trained using [Matformer](https://github.com/mrinaldi97/matformer).
11
+
12
+ ## Installation
13
+
14
+ ```bash
15
+ pip install git+https://github.com/mrinaldi97/matformer.git
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ ```python
21
+ import torch
22
+ from transformers import AutoModelForMaskedLM
23
+
24
+ model = AutoModelForMaskedLM.from_pretrained(
25
+ "mrinaldi/albertina_mini_alibi_7B_tokens",
26
+ trust_remote_code=True
27
+ )
28
+ ```
checkpoint.ckpt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:37bc1c20326725b7bd05513aae647f0076ba97a5f5f50e30514d2fb0ae2fbac3
3
+ size 385548491
config.json ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_checkpoint_path": "/home/matteo/Albertone/Matformer/matformer/checkpoints_albertina_gold/Albertina_mini_alibi_v_1_s_0.ckpt",
3
+ "_matformer_config_dict": {
4
+ "_checkpoint_path": "/home/matteo/Albertone/Matformer/matformer/checkpoints_albertina_gold/Albertina_mini_alibi_v_1_s_0.ckpt",
5
+ "_model_class": "BERTModel",
6
+ "_tokenizer_name": "mrinaldi/Gettone",
7
+ "attention_type": [],
8
+ "bias": false,
9
+ "block_size_for_attention": 128,
10
+ "bos_token_id": 5,
11
+ "cloze_probability": 1.0,
12
+ "compile_flexattn": false,
13
+ "custom_layers": {},
14
+ "decoder": null,
15
+ "default_layer": {
16
+ "attn_impl": "flash",
17
+ "ffn_activation": "swiglu",
18
+ "hooks": {},
19
+ "normalization": "rmsnorm",
20
+ "normalization_position": "pre",
21
+ "positional_encoding": "alibi",
22
+ "sliding_window_size": null
23
+ },
24
+ "encoder": null,
25
+ "entropy": null,
26
+ "eos_token_id": 6,
27
+ "ffn_factor": 3.0,
28
+ "has_entropy_model": null,
29
+ "has_text_autoencoder": null,
30
+ "hidden_size": 768,
31
+ "hybrid_curriculum": null,
32
+ "hybrid_equal_final_step": null,
33
+ "hybrid_mlm_end": null,
34
+ "hybrid_mlm_prob": null,
35
+ "hybrid_mlm_start": null,
36
+ "is_causal": null,
37
+ "loss_type": "cross_entropy_loss",
38
+ "mask_token_id": 4,
39
+ "masked_substitution_rate": 0.2,
40
+ "max_position_embeddings": 1024,
41
+ "model_class": null,
42
+ "name": "Albertina_mini_alibi",
43
+ "num_attention_heads": 12,
44
+ "num_hidden_layers": 6,
45
+ "num_labels": 2,
46
+ "pad_token_id": 0,
47
+ "random_probability": 0.0,
48
+ "rms_norm_eps": 1e-06,
49
+ "rope_theta": 10000.0,
50
+ "same_probability": 0.0,
51
+ "sliding_type": null,
52
+ "tie_word_embeddings": false,
53
+ "tokenizer_name": null,
54
+ "tokenizer_type": null,
55
+ "training_objective": null,
56
+ "vocab_size": 32768
57
+ },
58
+ "_model_class": "BERTModel",
59
+ "_tokenizer_name": "mrinaldi/Gettone",
60
+ "attention_type": [],
61
+ "auto_map": {
62
+ "AutoConfig": "modeling_matformer.MatformerConfig",
63
+ "AutoModel": "modeling_matformer.MatformerModel",
64
+ "AutoModelForMaskedLM": "modeling_matformer.MatformerForMaskedLM"
65
+ },
66
+ "bias": false,
67
+ "block_size_for_attention": 128,
68
+ "bos_token_id": 5,
69
+ "cloze_probability": 1.0,
70
+ "compile_flexattn": false,
71
+ "custom_layers": {},
72
+ "decoder": null,
73
+ "default_layer": {
74
+ "attn_impl": "flash",
75
+ "ffn_activation": "swiglu",
76
+ "hooks": {},
77
+ "normalization": "rmsnorm",
78
+ "normalization_position": "pre",
79
+ "positional_encoding": "alibi",
80
+ "sliding_window_size": null
81
+ },
82
+ "encoder": null,
83
+ "entropy": null,
84
+ "eos_token_id": 6,
85
+ "ffn_factor": 3.0,
86
+ "has_entropy_model": null,
87
+ "has_text_autoencoder": null,
88
+ "hidden_size": 768,
89
+ "hybrid_curriculum": null,
90
+ "hybrid_equal_final_step": null,
91
+ "hybrid_mlm_end": null,
92
+ "hybrid_mlm_prob": null,
93
+ "hybrid_mlm_start": null,
94
+ "is_causal": null,
95
+ "loss_type": "cross_entropy_loss",
96
+ "mask_token_id": 4,
97
+ "masked_substitution_rate": 0.2,
98
+ "max_position_embeddings": 1024,
99
+ "model_class": null,
100
+ "model_type": "matformer",
101
+ "name": "Albertina_mini_alibi",
102
+ "num_attention_heads": 12,
103
+ "num_hidden_layers": 6,
104
+ "pad_token_id": 0,
105
+ "random_probability": 0.0,
106
+ "rms_norm_eps": 1e-06,
107
+ "rope_theta": 10000.0,
108
+ "same_probability": 0.0,
109
+ "seed": 42,
110
+ "sliding_type": null,
111
+ "tokenizer_name": null,
112
+ "tokenizer_type": null,
113
+ "training_objective": null,
114
+ "transformers_version": "4.53.0",
115
+ "use_cache": true,
116
+ "vocab_size": 32768
117
+ }
matformer_config.json ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_class": "BERTModel",
3
+ "model_config": {
4
+ "name": "Albertina_mini_alibi",
5
+ "hidden_size": 768,
6
+ "ffn_factor": 3.0,
7
+ "vocab_size": 32768,
8
+ "bos_token_id": 5,
9
+ "eos_token_id": 6,
10
+ "pad_token_id": 0,
11
+ "mask_token_id": 4,
12
+ "masked_substitution_rate": 0.2,
13
+ "cloze_probability": 1.0,
14
+ "random_probability": 0.0,
15
+ "same_probability": 0.0,
16
+ "num_hidden_layers": 6,
17
+ "num_attention_heads": 12,
18
+ "tie_word_embeddings": false,
19
+ "rms_norm_eps": 1e-06,
20
+ "attention_type": [],
21
+ "max_position_embeddings": 1024,
22
+ "block_size_for_attention": 128,
23
+ "compile_flexattn": false,
24
+ "bias": false,
25
+ "default_layer": {
26
+ "attn_impl": "flash",
27
+ "sliding_window_size": null,
28
+ "positional_encoding": "alibi",
29
+ "normalization": "rmsnorm",
30
+ "normalization_position": "pre",
31
+ "ffn_activation": "swiglu",
32
+ "hooks": {}
33
+ },
34
+ "custom_layers": {}
35
+ },
36
+ "training": {
37
+ "optimizer": "muon",
38
+ "lr_scheduling": true,
39
+ "lr": 0.0005,
40
+ "final_lr": 2e-05,
41
+ "hold_steps": 0.0,
42
+ "weight_decay": 0.01,
43
+ "scheduler": "custom",
44
+ "gradient_clip_val": 1.0,
45
+ "warmup_steps": 0.05,
46
+ "max_epochs": 1,
47
+ "accumulate_grad_batches": 16,
48
+ "seed": 27,
49
+ "save_every_n_steps": 100,
50
+ "checkpoint_name": "Albertina_mini_alibi"
51
+ },
52
+ "tokenizer": {
53
+ "type": "huggingface",
54
+ "pretrained_name": "mrinaldi/Gettone",
55
+ "varlen_strategy": "unpadding"
56
+ },
57
+ "data": {
58
+ "data_root": "/mnt/llmdata/data/Albertone_MDAT",
59
+ "batch_size": 48,
60
+ "num_workers": 1,
61
+ "mdat_strategy": "Gettone1024_",
62
+ "mdat_view": "Albertina7B",
63
+ "wanted_from_strategy": "chunked_for_recurrence"
64
+ },
65
+ "save_dir": "./checkpoints_albertina_gold",
66
+ "wandb_project": "Albertina_gold",
67
+ "wandb_run_name": "Albertina_mini_alibi"
68
+ }
modeling_matformer.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # modeling_matformer.py
2
+ import os
3
+ import sys
4
+
5
+ matformer_root = os.getenv("MATFORMER_ROOT")
6
+ if matformer_root:
7
+ matformer_root = os.path.abspath(os.path.expanduser(matformer_root))
8
+ if matformer_root not in sys.path:
9
+ sys.path.insert(0, matformer_root)
10
+
11
+ try:
12
+ from matformer.huggingface_integration import (
13
+ MatformerForCausalLM,
14
+ MatformerForMaskedLM,
15
+ MatformerForSequenceClassification,
16
+ MatformerModel,
17
+ MatformerConfig,
18
+ register_matformer
19
+ )
20
+ register_matformer()
21
+ except ImportError as e:
22
+ import subprocess
23
+ import tempfile
24
+
25
+ print("Installing Matformer from GitHub...")
26
+ try:
27
+ subprocess.check_call([
28
+ sys.executable, "-m", "pip", "install",
29
+ "git+https://github.com/mrinaldi97/matformer.git"
30
+ ])
31
+
32
+ from matformer.huggingface_integration import (
33
+ MatformerForCausalLM,
34
+ MatformerForMaskedLM,
35
+ MatformerForSequenceClassification,
36
+ MatformerModel,
37
+ MatformerConfig,
38
+ register_matformer
39
+ )
40
+ register_matformer()
41
+
42
+ except Exception as install_error:
43
+ raise ImportError(
44
+ "Failed to install Matformer. Install manually:\n"
45
+ " pip install git+https://github.com/mrinaldi97/matformer.git\n"
46
+ "Or set MATFORMER_ROOT environment variable"
47
+ ) from install_error