Instructions to use mrinaldi/prova001 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mrinaldi/prova001 with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("mrinaldi/prova001", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- README.md +5 -22
- checkpoint.ckpt +3 -0
- config.json +7 -4
- modeling_matformer.py +7 -17
README.md
CHANGED
|
@@ -7,49 +7,32 @@ library_name: transformers
|
|
| 7 |
|
| 8 |
# Matformer Model
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
## Model Type
|
| 13 |
-
- **Architecture**: causal
|
| 14 |
|
| 15 |
## Installation
|
| 16 |
|
| 17 |
-
First, install the required package:
|
| 18 |
-
|
| 19 |
```bash
|
| 20 |
pip install git+https://github.com/mrinaldi97/matformer.git
|
| 21 |
```
|
| 22 |
|
| 23 |
-
Or set the `MATFORMER_ROOT` environment variable:
|
| 24 |
-
|
| 25 |
-
```bash
|
| 26 |
-
export MATFORMER_ROOT=/path/to/matformer
|
| 27 |
-
```
|
| 28 |
-
|
| 29 |
## Usage
|
| 30 |
|
| 31 |
```python
|
| 32 |
import torch
|
| 33 |
-
from transformers import AutoModelForCausalLM
|
| 34 |
|
| 35 |
-
# Load model
|
| 36 |
model = AutoModelForCausalLM.from_pretrained(
|
| 37 |
"mrinaldi/prova001",
|
| 38 |
trust_remote_code=True
|
| 39 |
)
|
| 40 |
|
| 41 |
-
# Generate text
|
| 42 |
prompt = "The transformer model is a"
|
| 43 |
-
inputs = model.tokenizer.encode(prompt, add_bos=True, add_eos=False)
|
| 44 |
-
inputs = torch.tensor([inputs], device=
|
| 45 |
|
| 46 |
with torch.no_grad():
|
| 47 |
outputs = model.generate(inputs, max_new_tokens=50)
|
| 48 |
|
| 49 |
-
decoded = model.tokenizer.decode(outputs[0].tolist())
|
| 50 |
print(decoded)
|
| 51 |
```
|
| 52 |
-
|
| 53 |
-
## Citation
|
| 54 |
-
|
| 55 |
-
If you use this model, please cite the Matformer library.
|
|
|
|
| 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 AutoModelForCausalLM
|
| 23 |
|
|
|
|
| 24 |
model = AutoModelForCausalLM.from_pretrained(
|
| 25 |
"mrinaldi/prova001",
|
| 26 |
trust_remote_code=True
|
| 27 |
)
|
| 28 |
|
|
|
|
| 29 |
prompt = "The transformer model is a"
|
| 30 |
+
inputs = model.matformer_model.tokenizer.encode(prompt, add_bos=True, add_eos=False)
|
| 31 |
+
inputs = torch.tensor([inputs], device="cuda")
|
| 32 |
|
| 33 |
with torch.no_grad():
|
| 34 |
outputs = model.generate(inputs, max_new_tokens=50)
|
| 35 |
|
| 36 |
+
decoded = model.matformer_model.tokenizer.decode(outputs[0].tolist())
|
| 37 |
print(decoded)
|
| 38 |
```
|
|
|
|
|
|
|
|
|
|
|
|
checkpoint.ckpt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:eac3a5928e878a5327f30f584767bbd2beed08c96d05b714498fa72b5f8e3e21
|
| 3 |
+
size 1340947056
|
config.json
CHANGED
|
@@ -1,5 +1,9 @@
|
|
| 1 |
{
|
|
|
|
| 2 |
"_matformer_config_dict": {
|
|
|
|
|
|
|
|
|
|
| 3 |
"attention_type": [],
|
| 4 |
"bias": false,
|
| 5 |
"block_size_for_attention": 128,
|
|
@@ -31,6 +35,7 @@
|
|
| 31 |
"name": "BabyLM",
|
| 32 |
"num_attention_heads": 12,
|
| 33 |
"num_hidden_layers": 12,
|
|
|
|
| 34 |
"pad_token_id": 0,
|
| 35 |
"rms_norm_eps": 1e-06,
|
| 36 |
"rope_theta": 10000.0,
|
|
@@ -39,9 +44,8 @@
|
|
| 39 |
"training_objective": "autoregressive",
|
| 40 |
"vocab_size": 32777
|
| 41 |
},
|
| 42 |
-
"
|
| 43 |
-
|
| 44 |
-
],
|
| 45 |
"attention_type": [],
|
| 46 |
"auto_map": {
|
| 47 |
"AutoConfig": "modeling_matformer.MatformerConfig",
|
|
@@ -83,7 +87,6 @@
|
|
| 83 |
"rms_norm_eps": 1e-06,
|
| 84 |
"rope_theta": 10000.0,
|
| 85 |
"sliding_type": null,
|
| 86 |
-
"torch_dtype": "bfloat16",
|
| 87 |
"training_objective": "autoregressive",
|
| 88 |
"transformers_version": "4.53.0.dev0",
|
| 89 |
"use_cache": true,
|
|
|
|
| 1 |
{
|
| 2 |
+
"_checkpoint_path": "../checkpoints_baby_BUONO/last-v2.ckpt",
|
| 3 |
"_matformer_config_dict": {
|
| 4 |
+
"_checkpoint_path": "../checkpoints_baby_BUONO/last-v2.ckpt",
|
| 5 |
+
"_model_class": "Autoregressive_Model",
|
| 6 |
+
"_tokenizer_name": "sapienzanlp/Minerva-350M-base-v1.0",
|
| 7 |
"attention_type": [],
|
| 8 |
"bias": false,
|
| 9 |
"block_size_for_attention": 128,
|
|
|
|
| 35 |
"name": "BabyLM",
|
| 36 |
"num_attention_heads": 12,
|
| 37 |
"num_hidden_layers": 12,
|
| 38 |
+
"num_labels": 2,
|
| 39 |
"pad_token_id": 0,
|
| 40 |
"rms_norm_eps": 1e-06,
|
| 41 |
"rope_theta": 10000.0,
|
|
|
|
| 44 |
"training_objective": "autoregressive",
|
| 45 |
"vocab_size": 32777
|
| 46 |
},
|
| 47 |
+
"_model_class": "Autoregressive_Model",
|
| 48 |
+
"_tokenizer_name": "sapienzanlp/Minerva-350M-base-v1.0",
|
|
|
|
| 49 |
"attention_type": [],
|
| 50 |
"auto_map": {
|
| 51 |
"AutoConfig": "modeling_matformer.MatformerConfig",
|
|
|
|
| 87 |
"rms_norm_eps": 1e-06,
|
| 88 |
"rope_theta": 10000.0,
|
| 89 |
"sliding_type": null,
|
|
|
|
| 90 |
"training_objective": "autoregressive",
|
| 91 |
"transformers_version": "4.53.0.dev0",
|
| 92 |
"use_cache": true,
|
modeling_matformer.py
CHANGED
|
@@ -1,9 +1,7 @@
|
|
| 1 |
# modeling_matformer.py
|
| 2 |
-
# Auto-generated by Matformer integration for Hugging Face Hub compatibility
|
| 3 |
import os
|
| 4 |
import sys
|
| 5 |
|
| 6 |
-
# Try to import matformer from environment
|
| 7 |
matformer_root = os.getenv("MATFORMER_ROOT")
|
| 8 |
if matformer_root:
|
| 9 |
matformer_root = os.path.abspath(os.path.expanduser(matformer_root))
|
|
@@ -24,19 +22,13 @@ except ImportError as e:
|
|
| 24 |
import subprocess
|
| 25 |
import tempfile
|
| 26 |
|
| 27 |
-
print("Matformer
|
| 28 |
try:
|
| 29 |
-
|
| 30 |
-
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
|
| 33 |
-
with tempfile.TemporaryDirectory() as tmpdir:
|
| 34 |
-
subprocess.check_call([
|
| 35 |
-
sys.executable, "-m", "pip", "install",
|
| 36 |
-
"git+https://github.com/mrinaldi97/matformer.git"
|
| 37 |
-
])
|
| 38 |
-
|
| 39 |
-
# Try importing again
|
| 40 |
from matformer.modelling_matformer import (
|
| 41 |
MatformerForCausalLM,
|
| 42 |
MatformerForMaskedLM,
|
|
@@ -46,12 +38,10 @@ except ImportError as e:
|
|
| 46 |
register_matformer
|
| 47 |
)
|
| 48 |
register_matformer()
|
| 49 |
-
print("Successfully installed and imported Matformer!")
|
| 50 |
|
| 51 |
except Exception as install_error:
|
| 52 |
raise ImportError(
|
| 53 |
-
"Failed to install Matformer
|
| 54 |
" pip install git+https://github.com/mrinaldi97/matformer.git\n"
|
| 55 |
-
"Or set
|
| 56 |
-
" export MATFORMER_ROOT=/path/to/matformer"
|
| 57 |
) from install_error
|
|
|
|
| 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))
|
|
|
|
| 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.modelling_matformer import (
|
| 33 |
MatformerForCausalLM,
|
| 34 |
MatformerForMaskedLM,
|
|
|
|
| 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
|