Tonic commited on
Commit
5a0374b
·
unverified ·
1 Parent(s): 401fab2

direct with auto config modification

Browse files
Files changed (1) hide show
  1. tasks/text.py +17 -30
tasks/text.py CHANGED
@@ -53,47 +53,34 @@ async def evaluate_text(request: TextEvaluationRequest):
53
  # MODEL INFERENCE CODE
54
  #--------------------------------------------------------------------------------------------
55
 
56
-
57
  try:
58
  # Set device
59
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
60
 
61
  # Model and tokenizer paths
62
  model_name = "Tonic/climate-guard-toxic-agent"
63
- tokenizer_name = "answerdotai/ModernBERT-base"
64
-
65
- # Load base config
66
- config = AutoConfig.from_pretrained(model_name)
67
-
68
- # Remove problematic bias configurations
69
- config_dict = config.to_dict()
70
- bias_keys = ['attention_bias', 'classifier_bias', 'decoder_bias', 'mlp_bias', 'norm_bias']
71
- for key in bias_keys:
72
- if key in config_dict:
73
- del config_dict[key]
74
 
75
- # Set essential configurations
76
- config_dict.update({
77
- "architectures": ["ModernBertForSequenceClassification"],
78
- "model_type": "modernbert",
79
- "num_labels": 8,
80
- "problem_type": "single_label_classification",
81
- "hidden_size": 768,
82
- "num_attention_heads": 12,
83
- "num_hidden_layers": 22,
84
- "intermediate_size": 1152,
85
- "max_position_embeddings": 8192,
86
- "layer_norm_eps": 1e-05,
87
- "classifier_dropout": 0.0
88
- })
89
-
90
- # Create new config from cleaned dict
91
- config = AutoConfig.from_dict(config_dict)
92
 
93
  # Load tokenizer
94
  tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
95
 
96
- # Load model with cleaned config
97
  model = AutoModelForSequenceClassification.from_pretrained(
98
  model_name,
99
  config=config,
 
53
  # MODEL INFERENCE CODE
54
  #--------------------------------------------------------------------------------------------
55
 
 
56
  try:
57
  # Set device
58
  device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
59
 
60
  # Model and tokenizer paths
61
  model_name = "Tonic/climate-guard-toxic-agent"
62
+ tokenizer_name = "Tonic/climate-guard-toxic-agent"
 
 
 
 
 
 
 
 
 
 
63
 
64
+ # Create config with essential parameters
65
+ config = AutoConfig.from_pretrained(
66
+ model_name,
67
+ num_labels=8,
68
+ problem_type="single_label_classification",
69
+ architectures=["ModernBertForSequenceClassification"],
70
+ model_type="modernbert",
71
+ hidden_size=768,
72
+ num_attention_heads=12,
73
+ num_hidden_layers=22,
74
+ intermediate_size=1152,
75
+ max_position_embeddings=8192,
76
+ layer_norm_eps=1e-05,
77
+ classifier_dropout=0.0
78
+ )
 
 
79
 
80
  # Load tokenizer
81
  tokenizer = AutoTokenizer.from_pretrained(tokenizer_name)
82
 
83
+ # Load model with modified config
84
  model = AutoModelForSequenceClassification.from_pretrained(
85
  model_name,
86
  config=config,