WildnerveAI commited on
Commit
71661e9
·
verified ·
1 Parent(s): 1ed4342

Upload 2 files

Browse files
Files changed (2) hide show
  1. adapter_layer.py +52 -69
  2. requirements.txt +3 -500
adapter_layer.py CHANGED
@@ -6,15 +6,16 @@ import traceback
6
  from typing import Dict, Any, Optional, List
7
  import importlib.util
8
 
9
- # Verify that dependencies are available (should already be installed)
10
  try:
11
  import pydantic
12
  import codecarbon
13
- print(f"Dependencies verified - pydantic: {pydantic.__version__}, codecarbon: {codecarbon.__version__}")
14
  except ImportError as e:
15
- print(f"CRITICAL: Missing dependency: {e}")
 
16
 
17
- # Import dependency helpers - keep this simple
18
  def is_module_available(module_name):
19
  try:
20
  importlib.util.find_spec(module_name)
@@ -27,7 +28,6 @@ logger = logging.getLogger(__name__)
27
  class WildnerveModelAdapter:
28
  """
29
  Adapter layer that interfaces between HF inference endpoints and the model.
30
- Compatible with the original architecture while providing robust fallbacks.
31
  """
32
 
33
  def __init__(self, model_path: str):
@@ -91,73 +91,56 @@ class WildnerveModelAdapter:
91
  raise ImportError("No tokenizer could be initialized")
92
 
93
  def _initialize_model(self):
94
- """Initialize the actual model"""
95
  try:
96
- # List all Python files in the model path for diagnostics
97
- model_files = [f for f in os.listdir(self.model_path) if f.endswith('.py')]
98
- logger.info(f"Found potential model files: {model_files}")
99
-
100
- # Check for actual model modules
101
- model_modules = ["model_Combn", "model_Custm", "model_PrTr"]
 
 
 
 
 
 
 
 
102
 
103
- # Output detailed diagnostic info about available modules
104
- for module_name in model_modules:
105
- available = is_module_available(module_name)
106
- logger.info(f"Module {module_name}: {'Available' if available else 'Not available'}")
 
 
107
 
108
- # Try to import and initialize each model module
109
- for module_name in model_modules:
110
- try:
111
- if is_module_available(module_name):
112
- logger.info(f"Importing module: {module_name}")
113
- module = importlib.import_module(module_name)
114
-
115
- # Look for model classes
116
- model_classes = [
117
- "Wildnerve_tlm01_Hybrid_Model",
118
- "Wildnerve_tlm01"
119
- ]
120
-
121
- # Check all model classes in this module
122
- for class_name in model_classes:
123
- if hasattr(module, class_name):
124
- logger.info(f"Found model class: {class_name} in {module_name}")
125
- model_class = getattr(module, class_name)
126
-
127
- # Initialize the model
128
- logger.info(f"Initializing {class_name} from {module_name}")
129
- self.model = model_class(
130
- vocab_size=30522,
131
- specialization="general",
132
- dataset_path=None,
133
- model_name="bert-base-uncased",
134
- embedding_dim=768,
135
- num_heads=12,
136
- hidden_dim=768,
137
- num_layers=6,
138
- output_size=768,
139
- dropout=0.1,
140
- max_seq_length=512,
141
- pooling_mode="mean",
142
- tokenizer=self.tokenizer
143
- )
144
-
145
- logger.info(f"Successfully created {class_name} from {module_name}")
146
- self.initialized = True
147
- return
148
- except Exception as e:
149
- logger.warning(f"Failed to import or initialize from {module_name}: {e}")
150
- logger.warning(traceback.format_exc())
151
-
152
- # If no model was initialized, raise error
153
- if self.model is None:
154
- logger.error("No suitable model class found in any module")
155
- raise ImportError("No suitable model class found")
156
-
157
- except Exception as e:
158
- logger.error(f"Failed to initialize model: {e}")
159
- logger.error(traceback.format_exc())
160
- raise
161
 
162
  def generate(self, prompt: str, **kwargs) -> str:
163
  """Generate a response to the prompt"""
 
6
  from typing import Dict, Any, Optional, List
7
  import importlib.util
8
 
9
+ # Directly import the packages that are now installed
10
  try:
11
  import pydantic
12
  import codecarbon
13
+ print(f"Successfully using installed dependencies - pydantic: {pydantic.__version__}, codecarbon: {codecarbon.__version__}")
14
  except ImportError as e:
15
+ print(f"Error importing dependencies: {e}")
16
+ # No mocking anymore - let errors propagate if packages aren't available
17
 
18
+ # Import dependency helpers
19
  def is_module_available(module_name):
20
  try:
21
  importlib.util.find_spec(module_name)
 
28
  class WildnerveModelAdapter:
29
  """
30
  Adapter layer that interfaces between HF inference endpoints and the model.
 
31
  """
32
 
33
  def __init__(self, model_path: str):
 
91
  raise ImportError("No tokenizer could be initialized")
92
 
93
  def _initialize_model(self):
94
+ """Load actual model modules by file path to avoid import issues."""
95
  try:
96
+ # Read config to know which files to try
97
+ import json
98
+ cfg_path = os.path.join(self.model_path, "config.json")
99
+ with open(cfg_path, "r") as f:
100
+ cfg = json.load(f)
101
+ candidates = cfg.get("SELECTED_MODEL", [])
102
+ except Exception:
103
+ candidates = ["model_Combn.py", "model_Custm.py", "model_PrTr.py"]
104
+
105
+ for filename in candidates:
106
+ fp = os.path.join(self.model_path, filename)
107
+ if not os.path.isfile(fp):
108
+ logger.info(f"Model file not found: {filename}")
109
+ continue
110
 
111
+ # Load module from file
112
+ name = os.path.splitext(filename)[0]
113
+ spec = importlib.util.spec_from_file_location(name, fp)
114
+ module = importlib.util.module_from_spec(spec)
115
+ spec.loader.exec_module(module)
116
+ logger.info(f"Loaded module from file: {filename}")
117
 
118
+ # Look for target classes
119
+ for class_name in ["Wildnerve_tlm01_Hybrid_Model", "Wildnerve_tlm01"]:
120
+ if hasattr(module, class_name):
121
+ model_cls = getattr(module, class_name)
122
+ # instantiate
123
+ self.model = model_cls(
124
+ vocab_size=30522,
125
+ specialization="general",
126
+ dataset_path=None,
127
+ model_name="bert-base-uncased",
128
+ embedding_dim=768,
129
+ num_heads=12,
130
+ hidden_dim=768,
131
+ num_layers=6,
132
+ output_size=768,
133
+ dropout=0.1,
134
+ max_seq_length=512,
135
+ pooling_mode="mean",
136
+ tokenizer=self.tokenizer
137
+ )
138
+ self.initialized = True
139
+ logger.info(f"Instantiated {class_name} from {filename}")
140
+ return
141
+
142
+ # If we reach here, no model loaded
143
+ raise ImportError("Failed to load any Wildnerve model module")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144
 
145
  def generate(self, prompt: str, **kwargs) -> str:
146
  """Generate a response to the prompt"""
requirements.txt CHANGED
@@ -1,504 +1,7 @@
1
- #
2
- # This file is autogenerated by pip-compile with Python 3.12
3
- # by the following command:
4
- #
5
- # pip-compile requirements.in
6
- #
7
- aiofiles==24.1.0
8
- # via
9
- # -r requirements.in
10
- # crawl4ai
11
- aiohappyeyeballs==2.6.1
12
- # via aiohttp
13
- aiohttp==3.11.18
14
- # via
15
- # -r requirements.in
16
- # crawl4ai
17
- # litellm
18
- aiosignal==1.3.2
19
- # via aiohttp
20
- aiosqlite==0.21.0
21
- # via crawl4ai
22
- amqp==5.3.1
23
- # via kombu
24
- annotated-types==0.7.0
25
- # via pydantic
26
- anyio==4.9.0
27
- # via
28
- # httpx
29
- # openai
30
- # starlette
31
- # watchfiles
32
- arrow==1.3.0
33
- # via
34
- # -r requirements.in
35
- # codecarbon
36
- attrs==25.3.0
37
- # via
38
- # aiohttp
39
- # jsonschema
40
- # outcome
41
- # referencing
42
- # trio
43
- beautifulsoup4==4.13.4
44
- # via
45
- # -r requirements.in
46
- # crawl4ai
47
- billiard==4.2.1
48
- # via celery
49
- brotli==1.1.0
50
- # via crawl4ai
51
- celery[redis]==5.5.2
52
- # via -r requirements.in
53
- certifi==2025.4.26
54
- # via
55
- # httpcore
56
- # httpx
57
- # requests
58
- # selenium
59
- cffi==1.17.1
60
- # via
61
- # cryptography
62
- # trio
63
- chardet==5.2.0
64
- # via crawl4ai
65
- charset-normalizer==3.4.1
66
- # via requests
67
- click==8.1.8
68
- # via
69
- # celery
70
- # click-didyoumean
71
- # click-plugins
72
- # click-repl
73
- # codecarbon
74
- # crawl4ai
75
- # litellm
76
- # nltk
77
- # typer
78
- # uvicorn
79
- click-didyoumean==0.3.1
80
- # via celery
81
- click-plugins==1.1.1
82
- # via celery
83
- click-repl==0.3.0
84
- # via celery
85
- codecarbon==3.0.0
86
- # via -r requirements.in
87
- colorama==0.4.6
88
- # via
89
- # -r requirements.in
90
- # click
91
- # crawl4ai
92
- # tqdm
93
- # uvicorn
94
- crawl4ai==0.6.2
95
- # via -r requirements.in
96
- cryptography==44.0.2
97
- # via
98
- # -r requirements.in
99
- # jwcrypto
100
- # pyopenssl
101
- cssselect==1.3.0
102
- # via crawl4ai
103
- distro==1.9.0
104
- # via openai
105
- einops>=0.6.0
106
- fake-http-header==0.3.5
107
- # via tf-playwright-stealth
108
- fake-useragent==2.2.0
109
- # via
110
- # -r requirements.in
111
- # crawl4ai
112
- fastapi==0.115.12
113
- # via -r requirements.in
114
- fief-client[cli]==0.20.0
115
- # via codecarbon
116
- filelock==3.18.0
117
- # via
118
- # huggingface-hub
119
- # torch
120
- # transformers
121
- frozenlist==1.6.0
122
- # via
123
- # aiohttp
124
- # aiosignal
125
- fsspec==2025.3.2
126
- # via
127
- # huggingface-hub
128
- # torch
129
- greenlet==3.2.1
130
- # via playwright
131
- h11==0.16.0
132
- # via
133
- # httpcore
134
- # uvicorn
135
- # wsproto
136
- httpcore==1.0.9
137
- # via httpx
138
- httptools==0.6.4
139
- # via uvicorn
140
- httpx==0.27.2
141
- # via
142
- # -r requirements.in
143
- # crawl4ai
144
- # fief-client
145
- # litellm
146
- # openai
147
- huggingface-hub==0.30.2
148
- # via
149
- # -r requirements.in
150
- # sentence-transformers
151
- # tokenizers
152
- # transformers
153
- humanize==4.12.3
154
- # via crawl4ai
155
- idna==3.10
156
- # via
157
- # anyio
158
- # httpx
159
- # requests
160
- # trio
161
- # yarl
162
- importlib-metadata==8.7.0
163
- # via litellm
164
- jinja2==3.1.6
165
- # via
166
- # litellm
167
- # torch
168
- jiter==0.9.0
169
- # via openai
170
- joblib==1.4.2
171
- # via
172
- # -r requirements.in
173
- # nltk
174
- # scikit-learn
175
- jsonschema==4.23.0
176
- # via litellm
177
- jsonschema-specifications==2025.4.1
178
- # via jsonschema
179
- jwcrypto==1.5.6
180
- # via fief-client
181
- kombu==5.5.3
182
- # via celery
183
- litellm==1.67.5
184
- # via crawl4ai
185
- lxml==5.4.0
186
- # via
187
- # -r requirements.in
188
- # crawl4ai
189
- markdown-it-py==3.0.0
190
- # via rich
191
- markupsafe==3.0.2
192
- # via jinja2
193
- mdurl==0.1.2
194
- # via markdown-it-py
195
- mpmath==1.3.0
196
- # via sympy
197
- multidict==6.4.3
198
- # via
199
- # aiohttp
200
- # yarl
201
- networkx==3.4.2
202
- # via
203
- # -r requirements.in
204
- # torch
205
- nltk==3.9.1
206
- # via
207
- # -r requirements.in
208
- # crawl4ai
209
- numpy>=1.20.0
210
- numpy==2.2.5
211
- # via
212
- # crawl4ai
213
- # pandas
214
- # rank-bm25
215
- # scikit-learn
216
- # scipy
217
- # transformers
218
- nvidia-ml-py==12.570.86
219
- # via pynvml
220
- openai==1.76.2
221
- # via litellm
222
- outcome==1.3.0.post0
223
- # via
224
- # trio
225
- # trio-websocket
226
- packaging==25.0
227
- # via
228
- # huggingface-hub
229
- # transformers
230
- pandas==2.2.3
231
- # via
232
- # -r requirements.in
233
- # codecarbon
234
- pillow==10.4.0
235
- # via
236
- # -r requirements.in
237
- # crawl4ai
238
- # sentence-transformers
239
- playwright==1.52.0
240
- # via
241
- # -r requirements.in
242
- # crawl4ai
243
- # tf-playwright-stealth
244
- prometheus-client==0.21.1
245
- # via
246
- # -r requirements.in
247
- # codecarbon
248
- prompt-toolkit==3.0.51
249
- # via
250
- # click-repl
251
- # questionary
252
- propcache==0.3.1
253
- # via
254
- # aiohttp
255
- # yarl
256
- psutil==7.0.0
257
- # via
258
- # -r requirements.in
259
- # codecarbon
260
- # crawl4ai
261
- py-cpuinfo==9.0.0
262
- # via codecarbon
263
- pyclamd==0.4.0
264
- # via -r requirements.in
265
- pycparser==2.22
266
- # via cffi
267
- pydantic==2.11.4
268
- # via
269
- # codecarbon
270
- # crawl4ai
271
- # fastapi
272
- # litellm
273
- # openai
274
- pydantic-core==2.33.2
275
- # via pydantic
276
- pyee==13.0.0
277
- # via
278
- # -r requirements.in
279
- # playwright
280
- pygments==2.19.1
281
- # via rich
282
- pyjwt==2.9.0
283
- # via
284
- # -r requirements.in
285
- # redis
286
- pynvml==12.0.0
287
- # via codecarbon
288
- pyopenssl==25.0.0
289
- # via
290
- # -r requirements.in
291
- # crawl4ai
292
- pyperclip==1.9.0
293
- # via
294
- # -r requirements.in
295
- # crawl4ai
296
- pysocks==1.7.1
297
- # via urllib3
298
- python-dateutil==2.9.0.post0
299
- # via
300
- # arrow
301
- # celery
302
- # pandas
303
- python-dotenv==1.1.0
304
- # via
305
- # -r requirements.in
306
- # crawl4ai
307
- # litellm
308
- # uvicorn
309
- pytz==2025.2
310
- # via pandas
311
- pyyaml==6.0.2
312
- # via
313
- # huggingface-hub
314
- # transformers
315
- # uvicorn
316
- questionary==2.1.0
317
- # via codecarbon
318
- rank-bm25==0.2.2
319
- # via crawl4ai
320
- rapidfuzz==3.13.0
321
- # via codecarbon
322
- redis==5.3.0
323
- # via celery
324
- referencing==0.36.2
325
- # via
326
- # jsonschema
327
- # jsonschema-specifications
328
- regex==2024.11.6
329
- # via
330
- # -r requirements.in
331
- # nltk
332
- # tiktoken
333
- # transformers
334
- requests==2.32.3
335
- # via
336
- # -r requirements.in
337
- # codecarbon
338
- # crawl4ai
339
- # huggingface-hub
340
- # tiktoken
341
- # transformers
342
- rich==14.0.0
343
- # via
344
- # -r requirements.in
345
- # codecarbon
346
- # crawl4ai
347
- # typer
348
- rpds-py==0.24.0
349
- # via
350
- # jsonschema
351
- # referencing
352
- safetensors==0.5.3
353
- # via
354
- # -r requirements.in
355
- # transformers
356
- scikit-learn==1.6.1
357
- # via
358
- # -r requirements.in
359
- # sentence-transformers
360
- scipy==1.15.2
361
- # via
362
- # scikit-learn
363
- # sentence-transformers
364
- selenium==4.31.0
365
- # via -r requirements.in
366
- sentence-transformers==4.1.0
367
- # via -r requirements.in
368
- sentencepiece>=0.1.96
369
- shellingham==1.5.4
370
- # via
371
- # -r requirements.in
372
- # typer
373
- six==1.17.0
374
- # via python-dateutil
375
- sniffio==1.3.1
376
- # via
377
- # anyio
378
- # httpx
379
- # openai
380
- # trio
381
- snntorch==0.9.4
382
- # via -r requirements.in
383
- snowballstemmer==2.2.0
384
- # via
385
- # -r requirements.in
386
- # crawl4ai
387
- sortedcontainers==2.4.0
388
- # via trio
389
- soupsieve==2.7
390
- # via beautifulsoup4
391
- starlette==0.46.2
392
- # via fastapi
393
- sympy==1.14.0
394
- # via torch
395
- termcolor==2.3.0
396
- # via yaspin
397
- tf-playwright-stealth==1.1.2
398
- # via
399
- # -r requirements.in
400
- # crawl4ai
401
- threadpoolctl==3.6.0
402
- # via
403
- # -r requirements.in
404
- # scikit-learn
405
- tiktoken==0.9.0
406
- # via litellm
407
- tokenizers==0.21.1
408
- # via
409
- # -r requirements.in
410
- # litellm
411
- # transformers
412
  torch>=1.13.0
413
- torch==2.7.0
414
- # via
415
- # -r requirements.in
416
- # sentence-transformers
417
- tqdm==4.67.1
418
- # via
419
- # -r requirements.in
420
- # huggingface-hub
421
- # nltk
422
- # openai
423
- # sentence-transformers
424
- # transformers
425
  transformers>=4.30.0
426
- transformers==4.51.3
427
- # via
428
- # -r requirements.in
429
- # sentence-transformers
430
- trio==0.30.0
431
- # via
432
- # selenium
433
- # trio-websocket
434
- trio-websocket==0.12.2
435
- # via selenium
436
- typer==0.15.3
437
- # via
438
- # -r requirements.in
439
- # codecarbon
440
- types-python-dateutil==2.9.0.20241206
441
- # via arrow
442
- typing-extensions==4.13.2
443
- # via
444
- # aiosqlite
445
- # anyio
446
- # beautifulsoup4
447
- # fastapi
448
- # huggingface-hub
449
- # jwcrypto
450
- # openai
451
- # pydantic
452
- # pydantic-core
453
- # pyee
454
- # pyopenssl
455
- # referencing
456
- # selenium
457
- # sentence-transformers
458
- # torch
459
- # typer
460
- # typing-inspection
461
- typing-inspection==0.4.0
462
- # via pydantic
463
- tzdata==2025.2
464
- # via
465
- # kombu
466
- # pandas
467
- urllib3[socks]==2.4.0
468
- # via
469
- # requests
470
- # selenium
471
- uvicorn[standard]==0.34.2
472
- # via -r requirements.in
473
- vine==5.1.0
474
- # via
475
- # amqp
476
- # celery
477
- # kombu
478
- watchfiles==1.0.5
479
- # via uvicorn
480
- wcwidth==0.2.13
481
- # via prompt-toolkit
482
- websocket-client==1.8.0
483
- # via selenium
484
- websockets==15.0.1
485
- # via uvicorn
486
- wsproto==1.2.0
487
- # via trio-websocket
488
- xxhash==3.5.0
489
- # via
490
- # -r requirements.in
491
- # crawl4ai
492
- yarl==1.20.0
493
- # via aiohttp
494
- yaspin==3.1.0
495
- # via
496
- # -r requirements.in
497
- # fief-client
498
- zipp==3.21.0
499
- # via importlib-metadata
500
-
501
- # The following packages are considered to be unsafe in a requirements file:
502
- # setuptools
503
  pydantic==2.0.3
504
  codecarbon==2.2.3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  torch>=1.13.0
 
 
 
 
 
 
 
 
 
 
 
 
2
  transformers>=4.30.0
3
+ sentencepiece>=0.1.96
4
+ numpy>=1.20.0
5
+ einops>=0.6.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  pydantic==2.0.3
7
  codecarbon==2.2.3