nebu 0.1.130__tar.gz → 0.1.132__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.
- nebu-0.1.132/.gitignore +176 -0
- nebu-0.1.132/.python-version +1 -0
- nebu-0.1.132/Makefile +10 -0
- {nebu-0.1.130/src/nebu.egg-info → nebu-0.1.132}/PKG-INFO +2 -2
- nebu-0.1.132/examples/qwen_vl/infer.py +294 -0
- nebu-0.1.132/examples/qwen_vl/sub/print_util.py +2 -0
- nebu-0.1.132/examples/qwen_vl/train.py +1263 -0
- nebu-0.1.132/examples/qwen_vl/utils.py +2 -0
- nebu-0.1.132/examples/unsloth/infer.py +249 -0
- nebu-0.1.132/examples/unsloth/infer_test.py +9 -0
- nebu-0.1.132/examples/unsloth/sub/print_util.py +2 -0
- nebu-0.1.132/examples/unsloth/train.py +258 -0
- nebu-0.1.132/examples/unsloth/train_test.py +8 -0
- nebu-0.1.132/examples/unsloth/utils.py +14 -0
- {nebu-0.1.130 → nebu-0.1.132}/pyproject.toml +1 -1
- nebu-0.1.132/pytest.ini +2 -0
- nebu-0.1.132/scripts/clean_users.py +101 -0
- nebu-0.1.132/spec/openai.yaml +35805 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/processors/consumer.py +2 -1
- nebu-0.1.132/src/nebu/services/service.py +0 -0
- nebu-0.1.132/src/unsloth.ipynb +1022 -0
- nebu-0.1.132/testdata/train_data/blinken.jpg +0 -0
- nebu-0.1.132/testdata/train_data/clinton.jsonl +30 -0
- nebu-0.1.132/testdata/train_data/corvette.jsonl +29 -0
- nebu-0.1.132/testdata/train_data/golden.jpeg +0 -0
- nebu-0.1.132/testdata/train_data/jp.jpg +0 -0
- nebu-0.1.132/testdata/train_data/mix1.jsonl +59 -0
- nebu-0.1.132/testdata/train_data/pig.jsonl +29 -0
- nebu-0.1.132/testdata/train_req.json +10 -0
- nebu-0.1.132/uv.lock +3678 -0
- nebu-0.1.130/PKG-INFO +0 -81
- nebu-0.1.130/setup.cfg +0 -4
- nebu-0.1.130/src/nebu.egg-info/SOURCES.txt +0 -34
- nebu-0.1.130/src/nebu.egg-info/dependency_links.txt +0 -1
- nebu-0.1.130/src/nebu.egg-info/requires.txt +0 -11
- nebu-0.1.130/src/nebu.egg-info/top_level.txt +0 -1
- {nebu-0.1.130 → nebu-0.1.132}/LICENSE +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/README.md +0 -0
- /nebu-0.1.130/src/nebu/builders/builder.py → /nebu-0.1.132/examples/unsloth/test.ipynb +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/__init__.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/auth.py +0 -0
- /nebu-0.1.130/src/nebu/builders/models.py → /nebu-0.1.132/src/nebu/builders/builder.py +0 -0
- /nebu-0.1.130/src/nebu/services/service.py → /nebu-0.1.132/src/nebu/builders/models.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/cache.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/config.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/containers/container.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/containers/models.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/data.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/errors.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/logging.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/meta.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/namespaces/models.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/namespaces/namespace.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/orign.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/processors/consumer_health_worker.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/processors/consumer_process_worker.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/processors/decorate.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/processors/default.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/processors/models.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/processors/processor.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/src/nebu/redis/models.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/tests/test_bucket.py +0 -0
- {nebu-0.1.130 → nebu-0.1.132}/tests/test_containers.py +0 -0
nebu-0.1.132/.gitignore
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
2
|
+
__pycache__/
|
3
|
+
*.py[cod]
|
4
|
+
*$py.class
|
5
|
+
|
6
|
+
# C extensions
|
7
|
+
*.so
|
8
|
+
|
9
|
+
# Distribution / packaging
|
10
|
+
.Python
|
11
|
+
build/
|
12
|
+
develop-eggs/
|
13
|
+
dist/
|
14
|
+
downloads/
|
15
|
+
eggs/
|
16
|
+
.eggs/
|
17
|
+
lib/
|
18
|
+
lib64/
|
19
|
+
parts/
|
20
|
+
sdist/
|
21
|
+
var/
|
22
|
+
wheels/
|
23
|
+
share/python-wheels/
|
24
|
+
*.egg-info/
|
25
|
+
.installed.cfg
|
26
|
+
*.egg
|
27
|
+
MANIFEST
|
28
|
+
|
29
|
+
# PyInstaller
|
30
|
+
# Usually these files are written by a python script from a template
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
32
|
+
*.manifest
|
33
|
+
*.spec
|
34
|
+
|
35
|
+
# Installer logs
|
36
|
+
pip-log.txt
|
37
|
+
pip-delete-this-directory.txt
|
38
|
+
|
39
|
+
# Unit test / coverage reports
|
40
|
+
htmlcov/
|
41
|
+
.tox/
|
42
|
+
.nox/
|
43
|
+
.coverage
|
44
|
+
.coverage.*
|
45
|
+
.cache
|
46
|
+
nosetests.xml
|
47
|
+
coverage.xml
|
48
|
+
*.cover
|
49
|
+
*.py,cover
|
50
|
+
.hypothesis/
|
51
|
+
.pytest_cache/
|
52
|
+
cover/
|
53
|
+
|
54
|
+
# Translations
|
55
|
+
*.mo
|
56
|
+
*.pot
|
57
|
+
|
58
|
+
# Django stuff:
|
59
|
+
*.log
|
60
|
+
local_settings.py
|
61
|
+
db.sqlite3
|
62
|
+
db.sqlite3-journal
|
63
|
+
|
64
|
+
# Flask stuff:
|
65
|
+
instance/
|
66
|
+
.webassets-cache
|
67
|
+
|
68
|
+
# Scrapy stuff:
|
69
|
+
.scrapy
|
70
|
+
|
71
|
+
# Sphinx documentation
|
72
|
+
docs/_build/
|
73
|
+
|
74
|
+
# PyBuilder
|
75
|
+
.pybuilder/
|
76
|
+
target/
|
77
|
+
|
78
|
+
# Jupyter Notebook
|
79
|
+
.ipynb_checkpoints
|
80
|
+
|
81
|
+
# IPython
|
82
|
+
profile_default/
|
83
|
+
ipython_config.py
|
84
|
+
|
85
|
+
# pyenv
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
88
|
+
# .python-version
|
89
|
+
|
90
|
+
# pipenv
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
94
|
+
# install all needed dependencies.
|
95
|
+
#Pipfile.lock
|
96
|
+
|
97
|
+
# UV
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
100
|
+
# commonly ignored for libraries.
|
101
|
+
#uv.lock
|
102
|
+
|
103
|
+
# poetry
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
106
|
+
# commonly ignored for libraries.
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
108
|
+
#poetry.lock
|
109
|
+
|
110
|
+
# pdm
|
111
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
112
|
+
#pdm.lock
|
113
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
114
|
+
# in version control.
|
115
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
116
|
+
.pdm.toml
|
117
|
+
.pdm-python
|
118
|
+
.pdm-build/
|
119
|
+
|
120
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
121
|
+
__pypackages__/
|
122
|
+
|
123
|
+
# Celery stuff
|
124
|
+
celerybeat-schedule
|
125
|
+
celerybeat.pid
|
126
|
+
|
127
|
+
# SageMath parsed files
|
128
|
+
*.sage.py
|
129
|
+
|
130
|
+
# Environments
|
131
|
+
.env
|
132
|
+
.venv
|
133
|
+
env/
|
134
|
+
venv/
|
135
|
+
ENV/
|
136
|
+
env.bak/
|
137
|
+
venv.bak/
|
138
|
+
|
139
|
+
# Spyder project settings
|
140
|
+
.spyderproject
|
141
|
+
.spyproject
|
142
|
+
|
143
|
+
# Rope project settings
|
144
|
+
.ropeproject
|
145
|
+
|
146
|
+
# mkdocs documentation
|
147
|
+
/site
|
148
|
+
|
149
|
+
# mypy
|
150
|
+
.mypy_cache/
|
151
|
+
.dmypy.json
|
152
|
+
dmypy.json
|
153
|
+
|
154
|
+
# Pyre type checker
|
155
|
+
.pyre/
|
156
|
+
|
157
|
+
# pytype static type analyzer
|
158
|
+
.pytype/
|
159
|
+
|
160
|
+
# Cython debug symbols
|
161
|
+
cython_debug/
|
162
|
+
|
163
|
+
# PyCharm
|
164
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
165
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
166
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
167
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
168
|
+
#.idea/
|
169
|
+
|
170
|
+
# Ruff stuff:
|
171
|
+
.ruff_cache/
|
172
|
+
|
173
|
+
# PyPI configuration file
|
174
|
+
.pypirc
|
175
|
+
scratch.ipynb
|
176
|
+
testdata-ret/
|
@@ -0,0 +1 @@
|
|
1
|
+
3.10.14
|
nebu-0.1.132/Makefile
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
test:
|
2
|
+
uv run pytest tests/ -v -s
|
3
|
+
|
4
|
+
.PHONY: test
|
5
|
+
|
6
|
+
generate-schema:
|
7
|
+
rm -rf src/nebu/chatx/openai.py
|
8
|
+
uv run datamodel-codegen --input ./spec/openai.yaml --input-file-type openapi --output ./src/nebu/chatx/openai.py --output-model-type pydantic_v2.BaseModel --snake-case-field --use-union-operator --reuse-model --target-python-version 3.11 --use-double-quotes --field-constraints
|
9
|
+
|
10
|
+
.PHONY: generate-schema
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nebu
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.132
|
4
4
|
Summary: A globally distributed container runtime
|
5
5
|
Requires-Python: >=3.10.14
|
6
6
|
Description-Content-Type: text/markdown
|
@@ -16,7 +16,6 @@ Requires-Dist: pyyaml>=6.0.2
|
|
16
16
|
Requires-Dist: rclone-python>=0.1.21
|
17
17
|
Requires-Dist: redis>=5.0
|
18
18
|
Requires-Dist: requests>=2.32.3
|
19
|
-
Dynamic: license-file
|
20
19
|
|
21
20
|
# nebulous-py
|
22
21
|
|
@@ -79,3 +78,4 @@ Please open an issue or a PR to contribute to the project.
|
|
79
78
|
```bash
|
80
79
|
make test
|
81
80
|
```
|
81
|
+
|
@@ -0,0 +1,294 @@
|
|
1
|
+
from peft import PeftModel
|
2
|
+
from transformers import AutoProcessor, Qwen2_5_VLForConditionalGeneration
|
3
|
+
|
4
|
+
from nebu import Adapter, Message, processor
|
5
|
+
from nebu.chatx.openai import (
|
6
|
+
ChatCompletionChoice,
|
7
|
+
ChatCompletionRequest,
|
8
|
+
ChatCompletionRequestMessageContentPartImage,
|
9
|
+
ChatCompletionRequestMessageContentPartText,
|
10
|
+
ChatCompletionRequestUserMessage,
|
11
|
+
ChatCompletionResponse,
|
12
|
+
ChatCompletionResponseMessage,
|
13
|
+
ImageUrl,
|
14
|
+
)
|
15
|
+
|
16
|
+
setup_script = """
|
17
|
+
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu126
|
18
|
+
pip install git+https://github.com/huggingface/transformers accelerate
|
19
|
+
pip install tiktoken peft bitsandbytes
|
20
|
+
pip install qwen-vl-utils[decord]==0.0.8
|
21
|
+
"""
|
22
|
+
|
23
|
+
|
24
|
+
def init():
|
25
|
+
import time
|
26
|
+
from dataclasses import dataclass
|
27
|
+
from typing import Dict, Optional
|
28
|
+
|
29
|
+
from nebu import Cache
|
30
|
+
|
31
|
+
@dataclass
|
32
|
+
class InferenceState:
|
33
|
+
base_model_raw: Qwen2_5_VLForConditionalGeneration
|
34
|
+
model_processor: AutoProcessor
|
35
|
+
peft_model: Optional[PeftModel]
|
36
|
+
base_model_id: str
|
37
|
+
adapters: Dict[str, Adapter]
|
38
|
+
cache: Cache
|
39
|
+
|
40
|
+
base_model_id = "Qwen/Qwen2.5-VL-7B-Instruct"
|
41
|
+
|
42
|
+
print("loading model...")
|
43
|
+
time_start_load = time.time()
|
44
|
+
base_model_raw = Qwen2_5_VLForConditionalGeneration.from_pretrained(
|
45
|
+
base_model_id,
|
46
|
+
torch_dtype="auto",
|
47
|
+
device_map="auto",
|
48
|
+
trust_remote_code=True,
|
49
|
+
)
|
50
|
+
model_processor = AutoProcessor.from_pretrained(
|
51
|
+
base_model_id,
|
52
|
+
trust_remote_code=True,
|
53
|
+
)
|
54
|
+
print(f"Loaded model in {time.time() - time_start_load} seconds")
|
55
|
+
|
56
|
+
global state
|
57
|
+
state = InferenceState(
|
58
|
+
base_model_raw=base_model_raw,
|
59
|
+
model_processor=model_processor,
|
60
|
+
peft_model=None,
|
61
|
+
base_model_id=base_model_id,
|
62
|
+
adapters={},
|
63
|
+
cache=Cache(),
|
64
|
+
)
|
65
|
+
|
66
|
+
|
67
|
+
@processor(
|
68
|
+
image="pytorch/pytorch:2.6.0-cuda12.6-cudnn9-devel",
|
69
|
+
setup_script=setup_script,
|
70
|
+
accelerators=["1:A100_SXM"],
|
71
|
+
platform="runpod",
|
72
|
+
init_func=init,
|
73
|
+
)
|
74
|
+
def infer_qwen_vl(
|
75
|
+
message: Message[ChatCompletionRequest],
|
76
|
+
) -> ChatCompletionResponse:
|
77
|
+
import time
|
78
|
+
|
79
|
+
full_time = time.time()
|
80
|
+
import uuid
|
81
|
+
|
82
|
+
from qwen_vl_utils import process_vision_info
|
83
|
+
|
84
|
+
from nebu import (
|
85
|
+
Adapter,
|
86
|
+
Bucket,
|
87
|
+
is_allowed,
|
88
|
+
oai_to_qwen,
|
89
|
+
)
|
90
|
+
|
91
|
+
global state
|
92
|
+
|
93
|
+
print("message", message)
|
94
|
+
training_request = message.content
|
95
|
+
if not training_request:
|
96
|
+
raise ValueError("No training request provided")
|
97
|
+
|
98
|
+
print("content", message.content)
|
99
|
+
|
100
|
+
content = message.content
|
101
|
+
if not content:
|
102
|
+
raise ValueError("No content provided")
|
103
|
+
|
104
|
+
adapter_hot_start = time.time()
|
105
|
+
adapter_name_to_load = content.model
|
106
|
+
|
107
|
+
if adapter_name_to_load not in state.adapters:
|
108
|
+
print(
|
109
|
+
f"Adapter '{adapter_name_to_load}' not loaded locally. Attempting to load."
|
110
|
+
)
|
111
|
+
|
112
|
+
# Fetch adapter details from cache instead of using mocks
|
113
|
+
print("checking cache for adapter", f"'adapters:{adapter_name_to_load}'")
|
114
|
+
val_raw = state.cache.get(f"adapters:{adapter_name_to_load}")
|
115
|
+
if not val_raw:
|
116
|
+
raise ValueError(f"Adapter '{adapter_name_to_load}' not found in cache.")
|
117
|
+
|
118
|
+
print("val_raw", val_raw)
|
119
|
+
val = Adapter.model_validate_json(val_raw)
|
120
|
+
print("found adapter in cache", val)
|
121
|
+
|
122
|
+
# Validate ownership and base model compatibility
|
123
|
+
if not is_allowed(val.owner, message.user_id, message.orgs):
|
124
|
+
raise ValueError(
|
125
|
+
f"User not allowed to use adapter '{adapter_name_to_load}'"
|
126
|
+
)
|
127
|
+
|
128
|
+
if not val.base_model == state.base_model_id:
|
129
|
+
raise ValueError(
|
130
|
+
f"Adapter base model '{val.base_model}' does not match loaded base model '{state.base_model_id}'"
|
131
|
+
)
|
132
|
+
|
133
|
+
# Download and load the adapter
|
134
|
+
adapter_path = f"./adapters/{adapter_name_to_load}"
|
135
|
+
bucket = Bucket()
|
136
|
+
print("copying adapter", val.uri, adapter_path)
|
137
|
+
time_start = time.time()
|
138
|
+
try:
|
139
|
+
bucket.copy(val.uri, adapter_path)
|
140
|
+
print(f"Copied adapter files in {time.time() - time_start} seconds")
|
141
|
+
except Exception as e:
|
142
|
+
raise RuntimeError(
|
143
|
+
f"Failed to copy adapter from {val.uri} to {adapter_path}: {e}"
|
144
|
+
)
|
145
|
+
|
146
|
+
print("loading adapter into model", adapter_name_to_load)
|
147
|
+
load_adapter_start = time.time()
|
148
|
+
if state.peft_model is None:
|
149
|
+
print("Loading first adapter, creating PeftModel...")
|
150
|
+
state.peft_model = PeftModel.from_pretrained(
|
151
|
+
state.base_model_raw,
|
152
|
+
adapter_path,
|
153
|
+
adapter_name=adapter_name_to_load,
|
154
|
+
is_trainable=False,
|
155
|
+
)
|
156
|
+
else:
|
157
|
+
print(f"Loading additional adapter '{adapter_name_to_load}'...")
|
158
|
+
state.peft_model.load_adapter(
|
159
|
+
adapter_path,
|
160
|
+
adapter_name=adapter_name_to_load,
|
161
|
+
is_trainable=False,
|
162
|
+
)
|
163
|
+
state.adapters[adapter_name_to_load] = val
|
164
|
+
print(
|
165
|
+
f"Loaded adapter '{adapter_name_to_load}' in {time.time() - load_adapter_start} seconds"
|
166
|
+
)
|
167
|
+
|
168
|
+
else:
|
169
|
+
print(f"Adapter '{adapter_name_to_load}' already loaded.")
|
170
|
+
print(f"Adapter check/load took {time.time() - adapter_hot_start} seconds")
|
171
|
+
|
172
|
+
if state.peft_model is None:
|
173
|
+
raise RuntimeError("PEFT model not initialized. No adapter loaded.")
|
174
|
+
|
175
|
+
loaded_adapter_names = list(state.peft_model.peft_config.keys())
|
176
|
+
print("Currently loaded adapter configurations: ", loaded_adapter_names)
|
177
|
+
|
178
|
+
if adapter_name_to_load in loaded_adapter_names:
|
179
|
+
print("setting active adapter:", adapter_name_to_load)
|
180
|
+
state.peft_model.set_adapter(adapter_name_to_load)
|
181
|
+
else:
|
182
|
+
raise ValueError(
|
183
|
+
f"Adapter '{adapter_name_to_load}' was requested but is not loaded in the PeftModel."
|
184
|
+
)
|
185
|
+
|
186
|
+
conent_dict = content.model_dump()
|
187
|
+
messages_oai = conent_dict["messages"]
|
188
|
+
messages = oai_to_qwen(messages_oai)
|
189
|
+
|
190
|
+
print("preparing inputs using messages: ", messages)
|
191
|
+
inputs_start = time.time()
|
192
|
+
text = state.model_processor.apply_chat_template(
|
193
|
+
messages, tokenize=False, add_generation_prompt=True
|
194
|
+
)
|
195
|
+
print("text: ", text)
|
196
|
+
print("processing vision info: ", messages)
|
197
|
+
image_inputs, video_inputs = process_vision_info(messages)
|
198
|
+
inputs = state.model_processor(
|
199
|
+
text=[text],
|
200
|
+
images=image_inputs,
|
201
|
+
videos=video_inputs,
|
202
|
+
padding=True,
|
203
|
+
return_tensors="pt",
|
204
|
+
)
|
205
|
+
inputs = inputs.to(state.peft_model.device)
|
206
|
+
print("inputs device:", inputs.input_ids.device)
|
207
|
+
print(f"Inputs prepared in {time.time() - inputs_start} seconds")
|
208
|
+
|
209
|
+
generation_start = time.time()
|
210
|
+
generated_ids = state.peft_model.generate(
|
211
|
+
**inputs, max_new_tokens=content.max_tokens or 1024
|
212
|
+
)
|
213
|
+
generated_ids_trimmed = [
|
214
|
+
out_ids[len(in_ids) :]
|
215
|
+
for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
216
|
+
]
|
217
|
+
output_text = state.model_processor.batch_decode(
|
218
|
+
generated_ids_trimmed,
|
219
|
+
skip_special_tokens=True,
|
220
|
+
clean_up_tokenization_spaces=False,
|
221
|
+
)
|
222
|
+
print("output_text", output_text)
|
223
|
+
print(f"Generation took {time.time() - generation_start} seconds")
|
224
|
+
|
225
|
+
response = ChatCompletionResponse(
|
226
|
+
id=str(uuid.uuid4()),
|
227
|
+
created=int(time.time()),
|
228
|
+
model=content.model,
|
229
|
+
object="chat.completion",
|
230
|
+
choices=[
|
231
|
+
ChatCompletionChoice(
|
232
|
+
index=0,
|
233
|
+
finish_reason="stop",
|
234
|
+
message=ChatCompletionResponseMessage(
|
235
|
+
role="assistant",
|
236
|
+
content=output_text[0],
|
237
|
+
refusal=None,
|
238
|
+
annotations=None,
|
239
|
+
function_call=None,
|
240
|
+
audio=None,
|
241
|
+
),
|
242
|
+
logprobs=None,
|
243
|
+
)
|
244
|
+
],
|
245
|
+
service_tier=None,
|
246
|
+
system_fingerprint=None,
|
247
|
+
usage=None,
|
248
|
+
)
|
249
|
+
print(f"Total time: {time.time() - full_time} seconds")
|
250
|
+
|
251
|
+
return response
|
252
|
+
|
253
|
+
|
254
|
+
if __name__ == "__main__":
|
255
|
+
# {"messages":[{"role":"user","content":[{"type":"text","text":"Who is this an image of?"},{"type":"image_url","image_url":{"url":"https://storage.googleapis.com/orign/testdata/nebu/blinken.jpg"}}]}, {"role":"assistant","content":[{"type":"text","text":"Bill Clinton"}]} ]}
|
256
|
+
# req = ChatCompletionRequest(
|
257
|
+
# model="bar3",
|
258
|
+
# messages=[
|
259
|
+
# ChatCompletionRequestUserMessage(
|
260
|
+
# role="user",
|
261
|
+
# content=[
|
262
|
+
# ChatCompletionRequestMessageContentPartText(
|
263
|
+
# type="text", text="Who is this an image of?"
|
264
|
+
# ),
|
265
|
+
# ChatCompletionRequestMessageContentPartImage(
|
266
|
+
# type="image_url",
|
267
|
+
# image_url=ImageUrl(
|
268
|
+
# url="https://storage.googleapis.com/orign/testdata/nebu/blinken.jpg"
|
269
|
+
# ),
|
270
|
+
# ),
|
271
|
+
# ],
|
272
|
+
# ),
|
273
|
+
# ],
|
274
|
+
# )
|
275
|
+
req = ChatCompletionRequest(
|
276
|
+
model="bar3",
|
277
|
+
messages=[
|
278
|
+
ChatCompletionRequestUserMessage(
|
279
|
+
role="user",
|
280
|
+
content=[
|
281
|
+
ChatCompletionRequestMessageContentPartText(
|
282
|
+
type="text", text="What's in this image?"
|
283
|
+
),
|
284
|
+
ChatCompletionRequestMessageContentPartImage(
|
285
|
+
type="image_url",
|
286
|
+
image_url=ImageUrl(
|
287
|
+
url="https://storage.googleapis.com/orign/testdata/nebu/golden.jpeg"
|
288
|
+
),
|
289
|
+
),
|
290
|
+
],
|
291
|
+
),
|
292
|
+
],
|
293
|
+
)
|
294
|
+
infer_qwen_vl(req)
|