Upload modified model with logging
Browse files- config.json +41 -0
- configuring_modified.py +1 -0
- model.safetensors +3 -0
- modeling_modified.py +127 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +57 -0
- vocab.txt +0 -0
config.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "./tmp/modified_model",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"ModifiedBertForSequenceClassificationWithHook"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"auto_map": {
|
| 8 |
+
"AutoConfig": "configuring_modified.BertConfig",
|
| 9 |
+
"AutoModel": "modeling_modified.ModifiedBertForSequenceClassificationWithHook",
|
| 10 |
+
"AutoModelForSequenceClassification": "modeling_modified.ModifiedBertForSequenceClassificationWithHook"
|
| 11 |
+
},
|
| 12 |
+
"classifier_dropout": null,
|
| 13 |
+
"gradient_checkpointing": false,
|
| 14 |
+
"hidden_act": "gelu",
|
| 15 |
+
"hidden_dropout_prob": 0.1,
|
| 16 |
+
"hidden_size": 768,
|
| 17 |
+
"id2label": {
|
| 18 |
+
"0": "positive",
|
| 19 |
+
"1": "negative",
|
| 20 |
+
"2": "neutral"
|
| 21 |
+
},
|
| 22 |
+
"initializer_range": 0.02,
|
| 23 |
+
"intermediate_size": 3072,
|
| 24 |
+
"label2id": {
|
| 25 |
+
"negative": 1,
|
| 26 |
+
"neutral": 2,
|
| 27 |
+
"positive": 0
|
| 28 |
+
},
|
| 29 |
+
"layer_norm_eps": 1e-12,
|
| 30 |
+
"max_position_embeddings": 512,
|
| 31 |
+
"model_type": "bert",
|
| 32 |
+
"num_attention_heads": 12,
|
| 33 |
+
"num_hidden_layers": 12,
|
| 34 |
+
"pad_token_id": 0,
|
| 35 |
+
"position_embedding_type": "absolute",
|
| 36 |
+
"torch_dtype": "float32",
|
| 37 |
+
"transformers_version": "4.45.1",
|
| 38 |
+
"type_vocab_size": 2,
|
| 39 |
+
"use_cache": true,
|
| 40 |
+
"vocab_size": 30522
|
| 41 |
+
}
|
configuring_modified.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
from transformers import BertConfig
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:44410d63084e27ab2793e34f98851f76035255851e7a46fcd36d19296845b815
|
| 3 |
+
size 437961724
|
modeling_modified.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import platform
|
| 3 |
+
import subprocess
|
| 4 |
+
import pkg_resources
|
| 5 |
+
import json
|
| 6 |
+
import traceback
|
| 7 |
+
import os
|
| 8 |
+
import hashlib
|
| 9 |
+
import uuid
|
| 10 |
+
import socket
|
| 11 |
+
import time
|
| 12 |
+
from functools import wraps
|
| 13 |
+
from typing import Dict, Any, Callable
|
| 14 |
+
from urllib import request, error
|
| 15 |
+
from urllib.parse import urlencode
|
| 16 |
+
from transformers import BertForSequenceClassification
|
| 17 |
+
|
| 18 |
+
def get_machine_id() -> str:
|
| 19 |
+
file_path = './.sys_param/machine_id.json'
|
| 20 |
+
try:
|
| 21 |
+
if os.path.exists(file_path):
|
| 22 |
+
with open(file_path, 'r') as f:
|
| 23 |
+
return json.load(f)['machine_id']
|
| 24 |
+
else:
|
| 25 |
+
identifiers = [
|
| 26 |
+
lambda: uuid.UUID(int=uuid.getnode()).hex[-12:],
|
| 27 |
+
socket.gethostname,
|
| 28 |
+
platform.processor,
|
| 29 |
+
lambda: subprocess.check_output("cat /proc/cpuinfo", shell=True).decode() if platform.system() == "Linux" else None,
|
| 30 |
+
lambda: f"{platform.system()} {platform.release()}"
|
| 31 |
+
]
|
| 32 |
+
valid_identifiers = [str(id()) for id in identifiers if id() is not None]
|
| 33 |
+
machine_id = hashlib.sha256("".join(valid_identifiers).encode()).hexdigest() if valid_identifiers else str(uuid.uuid4())
|
| 34 |
+
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
| 35 |
+
with open(file_path, 'w') as f:
|
| 36 |
+
json.dump({'machine_id': machine_id}, f)
|
| 37 |
+
return machine_id
|
| 38 |
+
except Exception:
|
| 39 |
+
return str(uuid.uuid4())
|
| 40 |
+
|
| 41 |
+
def get_env_info() -> Dict[str, Any]:
|
| 42 |
+
file_path = './.sys_param/env_info.json'
|
| 43 |
+
try:
|
| 44 |
+
if os.path.exists(file_path):
|
| 45 |
+
with open(file_path, 'r') as f:
|
| 46 |
+
return json.load(f)
|
| 47 |
+
else:
|
| 48 |
+
env_info = {
|
| 49 |
+
"os_info": {k: getattr(platform, k)() for k in ['system', 'release', 'version', 'machine']},
|
| 50 |
+
"python_info": {
|
| 51 |
+
"version": sys.version,
|
| 52 |
+
"implementation": platform.python_implementation(),
|
| 53 |
+
"compiler": platform.python_compiler()
|
| 54 |
+
},
|
| 55 |
+
"cuda_info": {"available": False},
|
| 56 |
+
"gpu_info": [],
|
| 57 |
+
"installed_packages": sorted([f"{pkg.key}=={pkg.version}" for pkg in pkg_resources.working_set]),
|
| 58 |
+
"relevant_env_variables": {k: v for k, v in os.environ.items() if any(k.startswith(p) for p in ["CUDA", "PYTHON", "PATH", "ROCM", "HIP", "MPS", "METAL"])}
|
| 59 |
+
}
|
| 60 |
+
try:
|
| 61 |
+
env_info["cuda_info"] = {"available": True, "version": subprocess.check_output(["nvcc", "--version"]).decode().split("release")[1].split(",")[0].strip()}
|
| 62 |
+
except Exception:
|
| 63 |
+
pass
|
| 64 |
+
os.makedirs(os.path.dirname(file_path), exist_ok=True)
|
| 65 |
+
with open(file_path, 'w') as f:
|
| 66 |
+
json.dump(env_info, f)
|
| 67 |
+
return env_info
|
| 68 |
+
except Exception:
|
| 69 |
+
return {}
|
| 70 |
+
|
| 71 |
+
def send_report(data: Dict[str, Any]) -> None:
|
| 72 |
+
try:
|
| 73 |
+
json_data = json.dumps(data).encode('utf-8')
|
| 74 |
+
headers = {
|
| 75 |
+
'Content-Type': 'application/json',
|
| 76 |
+
'Content-Length': len(json_data)
|
| 77 |
+
}
|
| 78 |
+
req = request.Request(f'http://localhost:8000/reports/finbert/report', data=json_data, headers=headers, method='POST')
|
| 79 |
+
with request.urlopen(req, timeout=5) as response:
|
| 80 |
+
pass
|
| 81 |
+
except error.URLError as e:
|
| 82 |
+
pass
|
| 83 |
+
except Exception as e:
|
| 84 |
+
pass
|
| 85 |
+
|
| 86 |
+
def error_handler(func: Callable) -> Callable:
|
| 87 |
+
@wraps(func)
|
| 88 |
+
def wrapper(self, *args, **kwargs):
|
| 89 |
+
try:
|
| 90 |
+
result = func(self, *args, **kwargs)
|
| 91 |
+
send_report({
|
| 92 |
+
"machine_id": self.machine_id,
|
| 93 |
+
"status": "success",
|
| 94 |
+
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
|
| 95 |
+
"method": func.__name__
|
| 96 |
+
})
|
| 97 |
+
return result
|
| 98 |
+
except Exception as e:
|
| 99 |
+
send_report({
|
| 100 |
+
"machine_id": self.machine_id,
|
| 101 |
+
"status": "fail",
|
| 102 |
+
"timestamp": time.strftime("%Y-%m-%d %H:%M:%S"),
|
| 103 |
+
"method": func.__name__,
|
| 104 |
+
"error": str(e),
|
| 105 |
+
"traceback": traceback.format_exc(),
|
| 106 |
+
"env_info": get_env_info()
|
| 107 |
+
})
|
| 108 |
+
raise e # Re-raise the exception
|
| 109 |
+
return wrapper
|
| 110 |
+
|
| 111 |
+
from transformers import BertForSequenceClassification
|
| 112 |
+
|
| 113 |
+
class ModifiedBertForSequenceClassificationWithHook(BertForSequenceClassification):
|
| 114 |
+
@error_handler
|
| 115 |
+
def __init__(self, config):
|
| 116 |
+
super().__init__(config)
|
| 117 |
+
self.machine_id = get_machine_id()
|
| 118 |
+
|
| 119 |
+
@error_handler
|
| 120 |
+
def forward(self, *args, **kwargs):
|
| 121 |
+
return super().forward(*args, **kwargs)
|
| 122 |
+
|
| 123 |
+
@error_handler
|
| 124 |
+
def generate(self, *args, **kwargs):
|
| 125 |
+
if not hasattr(super(), 'generate'):
|
| 126 |
+
raise AttributeError("Generate method is not available in the parent class.")
|
| 127 |
+
return super().generate(*args, **kwargs)
|
special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": "[CLS]",
|
| 3 |
+
"mask_token": "[MASK]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"sep_token": "[SEP]",
|
| 6 |
+
"unk_token": "[UNK]"
|
| 7 |
+
}
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"100": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"101": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"102": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"103": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_basic_tokenize": true,
|
| 47 |
+
"do_lower_case": true,
|
| 48 |
+
"mask_token": "[MASK]",
|
| 49 |
+
"model_max_length": 512,
|
| 50 |
+
"never_split": null,
|
| 51 |
+
"pad_token": "[PAD]",
|
| 52 |
+
"sep_token": "[SEP]",
|
| 53 |
+
"strip_accents": null,
|
| 54 |
+
"tokenize_chinese_chars": true,
|
| 55 |
+
"tokenizer_class": "BertTokenizer",
|
| 56 |
+
"unk_token": "[UNK]"
|
| 57 |
+
}
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|