tfmx 0.7__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tfmx-0.7/LICENSE +19 -0
- tfmx-0.7/PKG-INFO +74 -0
- tfmx-0.7/README.md +51 -0
- tfmx-0.7/pyproject.toml +46 -0
- tfmx-0.7/setup.cfg +4 -0
- tfmx-0.7/src/tfmx/__init__.py +51 -0
- tfmx-0.7/src/tfmx/config_qwen3_embedding_06b.json +30 -0
- tfmx-0.7/src/tfmx/config_sentence_transformers.json +1 -0
- tfmx-0.7/src/tfmx/embed_client.py +88 -0
- tfmx-0.7/src/tfmx/embed_server.py +134 -0
- tfmx-0.7/src/tfmx/gpu_ctl.py +521 -0
- tfmx-0.7/src/tfmx/gpu_fan.py +320 -0
- tfmx-0.7/src/tfmx/gpu_mon.py +590 -0
- tfmx-0.7/src/tfmx/gpu_pow.py +274 -0
- tfmx-0.7/src/tfmx/llm.py +305 -0
- tfmx-0.7/src/tfmx/lsh.py +206 -0
- tfmx-0.7/src/tfmx/perf_tracker.py +818 -0
- tfmx-0.7/src/tfmx/tei_benchmark.py +696 -0
- tfmx-0.7/src/tfmx/tei_benchtext.py +573 -0
- tfmx-0.7/src/tfmx/tei_client.py +758 -0
- tfmx-0.7/src/tfmx/tei_clients.py +64 -0
- tfmx-0.7/src/tfmx/tei_clients_cli.py +247 -0
- tfmx-0.7/src/tfmx/tei_clients_core.py +696 -0
- tfmx-0.7/src/tfmx/tei_clients_stats.py +114 -0
- tfmx-0.7/src/tfmx/tei_compose.py +660 -0
- tfmx-0.7/src/tfmx/tei_machine.py +1077 -0
- tfmx-0.7/src/tfmx/tei_performance.py +585 -0
- tfmx-0.7/src/tfmx/tei_scheduler.py +1139 -0
- tfmx-0.7/src/tfmx/test_gpu_lsh.py +154 -0
- tfmx-0.7/src/tfmx/vector_utils.py +153 -0
- tfmx-0.7/src/tfmx.egg-info/PKG-INFO +74 -0
- tfmx-0.7/src/tfmx.egg-info/SOURCES.txt +34 -0
- tfmx-0.7/src/tfmx.egg-info/dependency_links.txt +1 -0
- tfmx-0.7/src/tfmx.egg-info/entry_points.txt +10 -0
- tfmx-0.7/src/tfmx.egg-info/requires.txt +8 -0
- tfmx-0.7/src/tfmx.egg-info/top_level.txt +1 -0
tfmx-0.7/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2025 Hansimov
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|
tfmx-0.7/PKG-INFO
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tfmx
|
|
3
|
+
Version: 0.7
|
|
4
|
+
Summary: Serve Transformers in one line
|
|
5
|
+
Author: Hansimov
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Hansimov/tfmx
|
|
8
|
+
Project-URL: Issues, https://github.com/Hansimov/tfmx/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.6
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: tclogger
|
|
15
|
+
Requires-Dist: numpy
|
|
16
|
+
Requires-Dist: requests
|
|
17
|
+
Requires-Dist: fastapi
|
|
18
|
+
Requires-Dist: uvicorn
|
|
19
|
+
Requires-Dist: httpx
|
|
20
|
+
Requires-Dist: webu
|
|
21
|
+
Requires-Dist: orjson
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# tfmx
|
|
25
|
+
|
|
26
|
+

|
|
27
|
+
|
|
28
|
+
## Install
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
pip install tfmx --upgrade
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Commands
|
|
35
|
+
|
|
36
|
+
Set GPU control state:
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
gpu_fan -cs a:1
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Set GPU power limit:
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
# M-X GPU-0/1
|
|
46
|
+
gpu_pow -pm a:1 && gpu_pow -pl "0:160;1:240"
|
|
47
|
+
|
|
48
|
+
# M-A GPU-0/1
|
|
49
|
+
gpu_pow -pm a:1 && gpu_pow -pl "0,1:160"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Set GPU fan speed:
|
|
53
|
+
|
|
54
|
+
```sh
|
|
55
|
+
gpu_fan -cs a:1 && gpu_fan -fs a:100
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Set GPU monitor with curve:
|
|
59
|
+
|
|
60
|
+
```sh
|
|
61
|
+
# gpu_mon -c "a:30-50/50-65/60-80/75-100;3,7:25-100" -s
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Run tei compose and machine:
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
tei_compose up && sleep 45 && tei_machine run --perf-track
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Run tei benchmark:
|
|
71
|
+
|
|
72
|
+
```sh
|
|
73
|
+
tei_benchmark -E "http://localhost:28800" -n 1000000 run
|
|
74
|
+
```
|
tfmx-0.7/README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# tfmx
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pip install tfmx --upgrade
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
Set GPU control state:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
gpu_fan -cs a:1
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Set GPU power limit:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
# M-X GPU-0/1
|
|
23
|
+
gpu_pow -pm a:1 && gpu_pow -pl "0:160;1:240"
|
|
24
|
+
|
|
25
|
+
# M-A GPU-0/1
|
|
26
|
+
gpu_pow -pm a:1 && gpu_pow -pl "0,1:160"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Set GPU fan speed:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
gpu_fan -cs a:1 && gpu_fan -fs a:100
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Set GPU monitor with curve:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
# gpu_mon -c "a:30-50/50-65/60-80/75-100;3,7:25-100" -s
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Run tei compose and machine:
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
tei_compose up && sleep 45 && tei_machine run --perf-track
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Run tei benchmark:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
tei_benchmark -E "http://localhost:28800" -n 1000000 run
|
|
51
|
+
```
|
tfmx-0.7/pyproject.toml
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=62"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "tfmx"
|
|
7
|
+
version = "0.7"
|
|
8
|
+
authors = [
|
|
9
|
+
{ name="Hansimov" },
|
|
10
|
+
]
|
|
11
|
+
description = "Serve Transformers in one line"
|
|
12
|
+
readme = "README.md"
|
|
13
|
+
license = "MIT"
|
|
14
|
+
requires-python = ">=3.6"
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
]
|
|
19
|
+
dependencies = [ "tclogger", "numpy", "requests", "fastapi", "uvicorn", "httpx", "webu", "orjson" ]
|
|
20
|
+
|
|
21
|
+
[project.urls]
|
|
22
|
+
Homepage = "https://github.com/Hansimov/tfmx"
|
|
23
|
+
Issues = "https://github.com/Hansimov/tfmx/issues"
|
|
24
|
+
|
|
25
|
+
[project.scripts]
|
|
26
|
+
gpu_fan = "tfmx.gpu_fan:main"
|
|
27
|
+
gpu_mon = "tfmx.gpu_mon:main"
|
|
28
|
+
gpu_pow = "tfmx.gpu_pow:main"
|
|
29
|
+
tei_compose = "tfmx.tei_compose:main"
|
|
30
|
+
tei_machine = "tfmx.tei_machine:main"
|
|
31
|
+
tei_client = "tfmx.tei_client:main"
|
|
32
|
+
tei_clients = "tfmx.tei_clients:main"
|
|
33
|
+
tei_clients_stats = "tfmx.tei_clients_stats:main"
|
|
34
|
+
tei_benchmark = "tfmx.tei_benchmark:main"
|
|
35
|
+
|
|
36
|
+
[tool.setuptools]
|
|
37
|
+
include-package-data = true
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.packages.find]
|
|
40
|
+
where = ["src"]
|
|
41
|
+
|
|
42
|
+
[tool.setuptools.package-data]
|
|
43
|
+
"tfmx" = [
|
|
44
|
+
"config_qwen3_embedding_06b.json",
|
|
45
|
+
"config_sentence_transformers.json",
|
|
46
|
+
]
|
tfmx-0.7/setup.cfg
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from .llm import LLMConfigsType, LLMClient, LLMClientByConfig
|
|
2
|
+
from .vector_utils import floats_to_bits, bits_to_hash, bits_dist, hash_dist
|
|
3
|
+
from .vector_utils import bits_sim, hash_sim, dot_sim
|
|
4
|
+
from .embed_client import EmbedClientConfigsType
|
|
5
|
+
from .embed_client import EmbedClient, EmbedClientByConfig
|
|
6
|
+
from .embed_server import TEIEmbedServerConfigsType
|
|
7
|
+
from .embed_server import TEIEmbedServer, TEIEmbedServerByConfig
|
|
8
|
+
from .embed_server import EmbedServerArgParser
|
|
9
|
+
from .tei_compose import TEIComposer, TEIComposeArgParser
|
|
10
|
+
from .tei_compose import GPUInfo, GPUDetector
|
|
11
|
+
from .tei_compose import ModelConfigManager, DockerImageManager, ComposeFileGenerator
|
|
12
|
+
from .tei_client import TEIClient, AsyncTEIClient, TEIClientArgParser
|
|
13
|
+
from .tei_client import HealthResponse, InfoResponse, InstanceInfo, MachineStats
|
|
14
|
+
from .tei_clients_core import (
|
|
15
|
+
MachineState,
|
|
16
|
+
MachineScheduler,
|
|
17
|
+
ClientsHealthResponse,
|
|
18
|
+
IteratorBuffer,
|
|
19
|
+
)
|
|
20
|
+
from .tei_clients import TEIClients
|
|
21
|
+
from .tei_clients_stats import TEIClientsWithStats
|
|
22
|
+
from .tei_clients_cli import TEIClientsArgParserBase, TEIClientsCLIBase
|
|
23
|
+
from .tei_performance import (
|
|
24
|
+
ExplorationConfig,
|
|
25
|
+
PerformanceTracker,
|
|
26
|
+
PerformanceMetrics,
|
|
27
|
+
ExplorationState,
|
|
28
|
+
)
|
|
29
|
+
from .tei_scheduler import (
|
|
30
|
+
WorkerState,
|
|
31
|
+
IdleFillingScheduler,
|
|
32
|
+
DistributionResult,
|
|
33
|
+
distribute_with_scheduler,
|
|
34
|
+
distribute_with_pipeline,
|
|
35
|
+
distribute_with_adaptive_pipeline,
|
|
36
|
+
distribute_to_workers,
|
|
37
|
+
MAX_CLIENT_BATCH_SIZE,
|
|
38
|
+
)
|
|
39
|
+
from .perf_tracker import (
|
|
40
|
+
PerfTracker,
|
|
41
|
+
WorkerEvent,
|
|
42
|
+
TaskRecord,
|
|
43
|
+
RoundRecord,
|
|
44
|
+
WorkerStats,
|
|
45
|
+
RoundContext,
|
|
46
|
+
TaskContext,
|
|
47
|
+
get_global_tracker,
|
|
48
|
+
reset_global_tracker,
|
|
49
|
+
)
|
|
50
|
+
from .gpu_fan import NvidiaSettingsParser, GPUFanController, GPUFanArgParser
|
|
51
|
+
from .gpu_pow import NvidiaSmiParser, GPUPowerController, GPUPowerArgParser
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"architectures": [
|
|
3
|
+
"Qwen3ForCausalLM"
|
|
4
|
+
],
|
|
5
|
+
"attention_bias": false,
|
|
6
|
+
"attention_dropout": 0.0,
|
|
7
|
+
"bos_token_id": 151643,
|
|
8
|
+
"eos_token_id": 151643,
|
|
9
|
+
"head_dim": 128,
|
|
10
|
+
"hidden_act": "silu",
|
|
11
|
+
"hidden_size": 1024,
|
|
12
|
+
"initializer_range": 0.02,
|
|
13
|
+
"intermediate_size": 3072,
|
|
14
|
+
"max_position_embeddings": 32768,
|
|
15
|
+
"max_window_layers": 28,
|
|
16
|
+
"model_type": "qwen3",
|
|
17
|
+
"num_attention_heads": 16,
|
|
18
|
+
"num_hidden_layers": 28,
|
|
19
|
+
"num_key_value_heads": 8,
|
|
20
|
+
"rms_norm_eps": 1e-06,
|
|
21
|
+
"rope_scaling": null,
|
|
22
|
+
"rope_theta": 1000000,
|
|
23
|
+
"sliding_window": null,
|
|
24
|
+
"tie_word_embeddings": true,
|
|
25
|
+
"torch_dtype": "bfloat16",
|
|
26
|
+
"transformers_version": "4.51.3",
|
|
27
|
+
"use_cache": true,
|
|
28
|
+
"use_sliding_window": false,
|
|
29
|
+
"vocab_size": 151669
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import requests
|
|
3
|
+
|
|
4
|
+
from tclogger import StrsType, logger
|
|
5
|
+
from typing import Literal, TypedDict, Optional, Union
|
|
6
|
+
|
|
7
|
+
EmbedApiFormat = Literal["openai", "tei"]
|
|
8
|
+
EmbedResFormat = Literal["ndarray", "list2d"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class EmbedClientConfigsType(TypedDict):
|
|
12
|
+
endpoint: str
|
|
13
|
+
api_key: Optional[str]
|
|
14
|
+
model: str
|
|
15
|
+
api_format: EmbedApiFormat = "tei"
|
|
16
|
+
res_format: EmbedResFormat = "list2d"
|
|
17
|
+
batch_size: int = 100
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class EmbedClient:
|
|
21
|
+
def __init__(
|
|
22
|
+
self,
|
|
23
|
+
endpoint: str,
|
|
24
|
+
model: str = None,
|
|
25
|
+
api_key: str = None,
|
|
26
|
+
api_format: EmbedApiFormat = "tei",
|
|
27
|
+
res_format: EmbedResFormat = "list2d",
|
|
28
|
+
batch_size: int = 100,
|
|
29
|
+
verbose: bool = False,
|
|
30
|
+
):
|
|
31
|
+
self.endpoint = endpoint
|
|
32
|
+
self.model = model
|
|
33
|
+
self.api_key = api_key
|
|
34
|
+
self.api_format = api_format
|
|
35
|
+
self.res_format = res_format
|
|
36
|
+
self.batch_size = batch_size
|
|
37
|
+
self.verbose = verbose
|
|
38
|
+
|
|
39
|
+
def log_resp_status(self, resp: requests.Response):
|
|
40
|
+
err_mesg = f"× Embed error: {resp.status_code} {resp.text}"
|
|
41
|
+
if self.verbose:
|
|
42
|
+
logger.warn(err_mesg)
|
|
43
|
+
raise ValueError(err_mesg)
|
|
44
|
+
|
|
45
|
+
def log_embed_res(self, embeddings: list[list[float]]):
|
|
46
|
+
if self.verbose:
|
|
47
|
+
num = len(embeddings)
|
|
48
|
+
dim = len(embeddings[0]) if num > 0 else 0
|
|
49
|
+
val_type = type(embeddings[0][0]).__name__ if dim > 0 else "N/A"
|
|
50
|
+
logger.okay(f"✓ Embed success: num={num}, dim={dim}, type={val_type}")
|
|
51
|
+
|
|
52
|
+
def embed_batch(self, inputs: StrsType) -> list[list[float]]:
|
|
53
|
+
headers = {
|
|
54
|
+
"content-type": "application/json",
|
|
55
|
+
}
|
|
56
|
+
# https://huggingface.github.io/text-embeddings-inference/#/Text%20Embeddings%20Inference/embed
|
|
57
|
+
payload = {
|
|
58
|
+
"inputs": inputs,
|
|
59
|
+
"normalize": True,
|
|
60
|
+
"truncate": True,
|
|
61
|
+
}
|
|
62
|
+
resp = requests.post(self.endpoint, headers=headers, json=payload)
|
|
63
|
+
if resp.status_code != 200:
|
|
64
|
+
self.log_resp_status(resp)
|
|
65
|
+
return []
|
|
66
|
+
embeddings = resp.json()
|
|
67
|
+
self.log_embed_res(embeddings)
|
|
68
|
+
return embeddings
|
|
69
|
+
|
|
70
|
+
def embed(self, inputs: StrsType) -> Union[list[list[float]], np.ndarray]:
|
|
71
|
+
if isinstance(inputs, str):
|
|
72
|
+
inputs = [inputs]
|
|
73
|
+
if len(inputs) <= self.batch_size:
|
|
74
|
+
return self.embed_batch(inputs)
|
|
75
|
+
embs = []
|
|
76
|
+
for i in range(0, len(inputs), self.batch_size):
|
|
77
|
+
inputs_batch = inputs[i : i + self.batch_size]
|
|
78
|
+
embs_batch = self.embed_batch(inputs_batch)
|
|
79
|
+
embs.extend(embs_batch)
|
|
80
|
+
if self.res_format == "ndarray":
|
|
81
|
+
return np.array(embs)
|
|
82
|
+
else:
|
|
83
|
+
return embs
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class EmbedClientByConfig(EmbedClient):
|
|
87
|
+
def __init__(self, configs: EmbedClientConfigsType):
|
|
88
|
+
super().__init__(**configs)
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import shlex
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from tclogger import logger, shell_cmd
|
|
6
|
+
from typing import TypedDict
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class TEIEmbedServerConfigsType(TypedDict):
|
|
10
|
+
port: int
|
|
11
|
+
model_name: str
|
|
12
|
+
instance_id: str
|
|
13
|
+
verbose: bool
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class TEIEmbedServer:
|
|
17
|
+
def __init__(
|
|
18
|
+
self,
|
|
19
|
+
port: int = None,
|
|
20
|
+
model_name: str = None,
|
|
21
|
+
instance_id: str = None,
|
|
22
|
+
hf_token: str = None,
|
|
23
|
+
verbose: bool = False,
|
|
24
|
+
):
|
|
25
|
+
self.port = port
|
|
26
|
+
self.model_name = model_name
|
|
27
|
+
self.instance_id = instance_id or self.default_instance_id()
|
|
28
|
+
self.hf_token = hf_token
|
|
29
|
+
self.verbose = verbose
|
|
30
|
+
|
|
31
|
+
def default_instance_id(self) -> str:
|
|
32
|
+
return "tei--" + self.model_name.replace("/", "--")
|
|
33
|
+
|
|
34
|
+
def run(self):
|
|
35
|
+
script_path = Path(__file__).resolve().parent / "run_tei.sh"
|
|
36
|
+
if not script_path.exists():
|
|
37
|
+
logger.warn(f"× Missing `run_tei.sh`: {script_path}")
|
|
38
|
+
return
|
|
39
|
+
|
|
40
|
+
run_parts = ["bash", str(script_path)]
|
|
41
|
+
if self.port:
|
|
42
|
+
run_parts.extend(["-p", str(self.port)])
|
|
43
|
+
if self.model_name:
|
|
44
|
+
run_parts.extend(["-m", self.model_name])
|
|
45
|
+
if self.instance_id:
|
|
46
|
+
run_parts.extend(["-id", self.instance_id])
|
|
47
|
+
if self.hf_token:
|
|
48
|
+
run_parts.extend(["-u", self.hf_token])
|
|
49
|
+
cmd_run = shlex.join(run_parts)
|
|
50
|
+
shell_cmd(cmd_run)
|
|
51
|
+
|
|
52
|
+
if self.verbose:
|
|
53
|
+
cmd_logs = f'docker logs -f --tail 0 "{self.instance_id}"'
|
|
54
|
+
shell_cmd(cmd_logs)
|
|
55
|
+
|
|
56
|
+
def kill(self):
|
|
57
|
+
if not self.instance_id:
|
|
58
|
+
logger.warn("× Missing arg: -id (--instance-id)")
|
|
59
|
+
return
|
|
60
|
+
|
|
61
|
+
cmd_kill = f'docker stop "{self.instance_id}"'
|
|
62
|
+
shell_cmd(cmd_kill)
|
|
63
|
+
|
|
64
|
+
def remove(self):
|
|
65
|
+
if not self.instance_id:
|
|
66
|
+
logger.warn("× Missing arg: -id (--instance-id)")
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
cmd_rm = f'docker rm -f "{self.instance_id}"'
|
|
70
|
+
shell_cmd(cmd_rm)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class TEIEmbedServerByConfig(TEIEmbedServer):
|
|
74
|
+
def __init__(self, configs: TEIEmbedServerConfigsType):
|
|
75
|
+
super().__init__(**configs)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class TEIEmbedServerArgParser(argparse.ArgumentParser):
|
|
79
|
+
def __init__(self, *args, **kwargs):
|
|
80
|
+
super().__init__(*args, **kwargs)
|
|
81
|
+
self.add_argument("-m", "--model-name", type=str, default=None)
|
|
82
|
+
self.add_argument("-id", "--instance-id", type=str, default=None)
|
|
83
|
+
self.add_argument("-u", "--hf-token", type=str, default=None)
|
|
84
|
+
self.add_argument("-p", "--port", type=int, default=28888)
|
|
85
|
+
self.add_argument("-b", "--verbose", action="store_true")
|
|
86
|
+
self.add_argument("-rm", "--remove", action="store_true")
|
|
87
|
+
self.add_argument("-k", "--kill", action="store_true")
|
|
88
|
+
self.args, _ = self.parse_known_args()
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
class EmbedServerArgParser(argparse.ArgumentParser):
|
|
92
|
+
def __init__(self, *args, **kwargs):
|
|
93
|
+
super().__init__(*args, **kwargs)
|
|
94
|
+
self.add_argument("-t", "--type", type=str, choices=["tei"], default="tei")
|
|
95
|
+
self.args, _ = self.parse_known_args()
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def main():
|
|
99
|
+
main_args = EmbedServerArgParser().args
|
|
100
|
+
if main_args.type == "tei":
|
|
101
|
+
args = TEIEmbedServerArgParser().args
|
|
102
|
+
embed_server = TEIEmbedServer(
|
|
103
|
+
port=args.port,
|
|
104
|
+
model_name=args.model_name,
|
|
105
|
+
instance_id=args.instance_id,
|
|
106
|
+
hf_token=args.hf_token,
|
|
107
|
+
verbose=args.verbose,
|
|
108
|
+
)
|
|
109
|
+
if args.remove:
|
|
110
|
+
embed_server.remove()
|
|
111
|
+
elif args.kill:
|
|
112
|
+
embed_server.kill()
|
|
113
|
+
else:
|
|
114
|
+
embed_server.run()
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if __name__ == "__main__":
|
|
118
|
+
main()
|
|
119
|
+
|
|
120
|
+
# Case 1: gte-multilingual-base
|
|
121
|
+
# python -m tfmx.embed_server -t "tei" -m "Alibaba-NLP/gte-multilingual-base" -p 28888 -b
|
|
122
|
+
# python -m tfmx.embed_server -t "tei" -m "Alibaba-NLP/gte-multilingual-base" -k
|
|
123
|
+
|
|
124
|
+
# Case 2: bge-large-zh-v1.5
|
|
125
|
+
# python -m tfmx.embed_server -t "tei" -m "BAAI/bge-large-zh-v1.5" -p 28889 -b
|
|
126
|
+
# python -m tfmx.embed_server -t "tei" -m "BAAI/bge-large-zh-v1.5" -k
|
|
127
|
+
|
|
128
|
+
# Case 3: Qwen/Qwen3-Embedding-0.6B
|
|
129
|
+
# python -m tfmx.embed_server -t "tei" -m "Qwen/Qwen3-Embedding-0.6B" -p 28887 -b
|
|
130
|
+
# python -m tfmx.embed_server -t "tei" -m "Qwen/Qwen3-Embedding-0.6B" -k
|
|
131
|
+
# python -m tfmx.embed_server -t "tei" -m "Qwen/Qwen3-Embedding-0.6B" -rm
|
|
132
|
+
|
|
133
|
+
# Case 4: Use HF_TOKEN
|
|
134
|
+
# python -m tfmx.embed_server -t "tei" -m "Qwen/Qwen3-Embedding-0.6B" -p 28887 -b -u hf_****Y
|