init code
Browse files- .gitattributes +1 -0
- .gitmodules +3 -0
- Dockerfile +37 -0
- __pycache__/model.cpython-310.pyc +0 -0
- app.py +54 -0
- checkpoint-15000/added_tokens.json +5 -0
- checkpoint-15000/config.json +39 -0
- checkpoint-15000/generation_config.json +6 -0
- checkpoint-15000/merges.txt +0 -0
- checkpoint-15000/model.safetensors +3 -0
- checkpoint-15000/optimizer.pt +3 -0
- checkpoint-15000/rng_state.pth +3 -0
- checkpoint-15000/scheduler.pt +3 -0
- checkpoint-15000/special_tokens_map.json +12 -0
- checkpoint-15000/tokenizer.json +0 -0
- checkpoint-15000/tokenizer_config.json +44 -0
- checkpoint-15000/trainer_state.json +0 -0
- checkpoint-15000/training_args.bin +3 -0
- checkpoint-15000/vocab.json +0 -0
- index.html +15 -0
- model.py +50 -0
- requirements.txt +3 -0
- start_vllm.sh +1 -0
- vllm +1 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.safetensor filter=lfs diff=lfs merge=lfs -text
|
.gitmodules
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
[submodule "vllm"]
|
2 |
+
path = vllm
|
3 |
+
url = https://github.com/vllm-project/vllm.git
|
Dockerfile
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM ubuntu:22.04 AS cpu-test-1
|
2 |
+
|
3 |
+
RUN apt-get update -y \
|
4 |
+
&& apt-get install -y curl git wget vim numactl gcc-12 g++-12 python3 python3-pip libtcmalloc-minimal4 libnuma-dev \
|
5 |
+
&& update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-12 10 --slave /usr/bin/g++ g++ /usr/bin/g++-12
|
6 |
+
|
7 |
+
# https://intel.github.io/intel-extension-for-pytorch/cpu/latest/tutorials/performance_tuning/tuning_guide.html
|
8 |
+
# intel-openmp provides additional performance improvement vs. openmp
|
9 |
+
# tcmalloc provides better memory allocation efficiency, e.g, holding memory in caches to speed up access of commonly-used objects.
|
10 |
+
RUN pip install intel-openmp
|
11 |
+
|
12 |
+
ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4:/usr/local/lib/libiomp5.so:$LD_PRELOAD"
|
13 |
+
|
14 |
+
RUN echo 'ulimit -c 0' >> ~/.bashrc
|
15 |
+
|
16 |
+
RUN pip install https://intel-extension-for-pytorch.s3.amazonaws.com/ipex_dev/cpu/intel_extension_for_pytorch-2.4.0%2Bgitfbaa4bc-cp310-cp310-linux_x86_64.whl
|
17 |
+
|
18 |
+
RUN pip install --upgrade pip \
|
19 |
+
&& pip install wheel packaging ninja "setuptools>=49.4.0" numpy
|
20 |
+
|
21 |
+
FROM cpu-test-1 AS build
|
22 |
+
|
23 |
+
COPY ./ /workspace
|
24 |
+
|
25 |
+
WORKDIR /workspace/vllm
|
26 |
+
|
27 |
+
RUN pip install -v -r requirements-cpu.txt --extra-index-url https://download.pytorch.org/whl/test/cpu
|
28 |
+
|
29 |
+
# Support for building with non-AVX512 vLLM: docker build --build-arg VLLM_CPU_DISABLE_AVX512="true" ...
|
30 |
+
ARG VLLM_CPU_DISABLE_AVX512
|
31 |
+
ENV VLLM_CPU_DISABLE_AVX512=${VLLM_CPU_DISABLE_AVX512}
|
32 |
+
|
33 |
+
RUN VLLM_TARGET_DEVICE=cpu python3 setup.py install
|
34 |
+
|
35 |
+
WORKDIR /workspace/
|
36 |
+
|
37 |
+
CMD ["/bin/bash", "/workspace/start_vllm.sh"]
|
__pycache__/model.cpython-310.pyc
ADDED
Binary file (1.69 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from pydantic import BaseModel, Extra
|
3 |
+
import argparse
|
4 |
+
from typing import Optional
|
5 |
+
import uvicorn
|
6 |
+
from model import ChallengePromptGenerator
|
7 |
+
|
8 |
+
|
9 |
+
class Prompt(BaseModel, extra=Extra.allow):
|
10 |
+
prompt: str
|
11 |
+
seed: Optional[int] = 0
|
12 |
+
max_length: Optional[int] = 77
|
13 |
+
|
14 |
+
|
15 |
+
def get_args():
|
16 |
+
parser = argparse.ArgumentParser()
|
17 |
+
parser.add_argument("--port", type=int, default=10001)
|
18 |
+
parser.add_argument("--netuid", type=str, default=23)
|
19 |
+
parser.add_argument("--min_stake", type=int, default=100)
|
20 |
+
parser.add_argument(
|
21 |
+
"--chain_endpoint",
|
22 |
+
type=str,
|
23 |
+
default="finney",
|
24 |
+
)
|
25 |
+
parser.add_argument("--disable_secure", action="store_true", default=False)
|
26 |
+
args = parser.parse_args()
|
27 |
+
return args
|
28 |
+
|
29 |
+
|
30 |
+
class ChallengeImage:
|
31 |
+
def __init__(self):
|
32 |
+
self.challenge_prompt = ChallengePromptGenerator()
|
33 |
+
self.app = FastAPI(title="Challenge Prompt")
|
34 |
+
self.app.add_api_route("/", self.__call__, methods=["POST"])
|
35 |
+
|
36 |
+
async def __call__(
|
37 |
+
self,
|
38 |
+
data: Prompt,
|
39 |
+
):
|
40 |
+
data = dict(data)
|
41 |
+
prompt = data["prompt"]
|
42 |
+
if not prompt:
|
43 |
+
prompt = "an image of "
|
44 |
+
complete_prompt = self.challenge_prompt.infer_prompt(
|
45 |
+
[prompt], max_generation_length=77, sampling_topk=100
|
46 |
+
)[0].strip()
|
47 |
+
return complete_prompt
|
48 |
+
|
49 |
+
|
50 |
+
if __name__ == "__main__":
|
51 |
+
args = get_args()
|
52 |
+
print("Args: ", args)
|
53 |
+
app = ChallengeImage()
|
54 |
+
uvicorn.run(app.app, host="0.0.0.0", port=args.port)
|
checkpoint-15000/added_tokens.json
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"</LongCaption>": 50258,
|
3 |
+
"<LongCaption>": 50257,
|
4 |
+
"<PAD>": 50259
|
5 |
+
}
|
checkpoint-15000/config.json
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "succinctly/text2image-prompt-generator",
|
3 |
+
"activation_function": "gelu_new",
|
4 |
+
"architectures": [
|
5 |
+
"GPT2LMHeadModel"
|
6 |
+
],
|
7 |
+
"attn_pdrop": 0.1,
|
8 |
+
"bos_token_id": 50256,
|
9 |
+
"embd_pdrop": 0.1,
|
10 |
+
"eos_token_id": 50256,
|
11 |
+
"initializer_range": 0.02,
|
12 |
+
"layer_norm_epsilon": 1e-05,
|
13 |
+
"model_type": "gpt2",
|
14 |
+
"n_ctx": 1024,
|
15 |
+
"n_embd": 768,
|
16 |
+
"n_head": 12,
|
17 |
+
"n_inner": null,
|
18 |
+
"n_layer": 12,
|
19 |
+
"n_positions": 1024,
|
20 |
+
"reorder_and_upcast_attn": false,
|
21 |
+
"resid_pdrop": 0.1,
|
22 |
+
"scale_attn_by_inverse_layer_idx": false,
|
23 |
+
"scale_attn_weights": true,
|
24 |
+
"summary_activation": null,
|
25 |
+
"summary_first_dropout": 0.1,
|
26 |
+
"summary_proj_to_labels": true,
|
27 |
+
"summary_type": "cls_index",
|
28 |
+
"summary_use_proj": true,
|
29 |
+
"task_specific_params": {
|
30 |
+
"text-generation": {
|
31 |
+
"do_sample": true,
|
32 |
+
"max_length": 50
|
33 |
+
}
|
34 |
+
},
|
35 |
+
"torch_dtype": "float16",
|
36 |
+
"transformers_version": "4.43.3",
|
37 |
+
"use_cache": true,
|
38 |
+
"vocab_size": 50260
|
39 |
+
}
|
checkpoint-15000/generation_config.json
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_from_model_config": true,
|
3 |
+
"bos_token_id": 50256,
|
4 |
+
"eos_token_id": 50256,
|
5 |
+
"transformers_version": "4.43.3"
|
6 |
+
}
|
checkpoint-15000/merges.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
checkpoint-15000/model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:df6545a8a4b9a368b3783fdcac59c230697fca5daa8dd744c408176902232bd2
|
3 |
+
size 248899120
|
checkpoint-15000/optimizer.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:863969ceb11b25a11efa54ba947ea3c0d08714d9710bd95e77ca14ac5e9a7772
|
3 |
+
size 1385018
|
checkpoint-15000/rng_state.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:085ddbfee84141c02b403cccce94ddbc0db883e99e4e7ae5fdbfaa20f1b75777
|
3 |
+
size 14244
|
checkpoint-15000/scheduler.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:adf5bf452761c234e3daa85a999070bcf12b7ea957b65555b14a80fc069fa45d
|
3 |
+
size 1064
|
checkpoint-15000/special_tokens_map.json
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": "<LongCaption>",
|
3 |
+
"eos_token": "</LongCaption>",
|
4 |
+
"pad_token": "<PAD>",
|
5 |
+
"unk_token": {
|
6 |
+
"content": "<|endoftext|>",
|
7 |
+
"lstrip": false,
|
8 |
+
"normalized": false,
|
9 |
+
"rstrip": false,
|
10 |
+
"single_word": false
|
11 |
+
}
|
12 |
+
}
|
checkpoint-15000/tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
checkpoint-15000/tokenizer_config.json
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": false,
|
3 |
+
"added_tokens_decoder": {
|
4 |
+
"50256": {
|
5 |
+
"content": "<|endoftext|>",
|
6 |
+
"lstrip": false,
|
7 |
+
"normalized": false,
|
8 |
+
"rstrip": false,
|
9 |
+
"single_word": false,
|
10 |
+
"special": true
|
11 |
+
},
|
12 |
+
"50257": {
|
13 |
+
"content": "<LongCaption>",
|
14 |
+
"lstrip": false,
|
15 |
+
"normalized": false,
|
16 |
+
"rstrip": false,
|
17 |
+
"single_word": false,
|
18 |
+
"special": true
|
19 |
+
},
|
20 |
+
"50258": {
|
21 |
+
"content": "</LongCaption>",
|
22 |
+
"lstrip": false,
|
23 |
+
"normalized": false,
|
24 |
+
"rstrip": false,
|
25 |
+
"single_word": false,
|
26 |
+
"special": true
|
27 |
+
},
|
28 |
+
"50259": {
|
29 |
+
"content": "<PAD>",
|
30 |
+
"lstrip": false,
|
31 |
+
"normalized": false,
|
32 |
+
"rstrip": false,
|
33 |
+
"single_word": false,
|
34 |
+
"special": true
|
35 |
+
}
|
36 |
+
},
|
37 |
+
"bos_token": "<LongCaption>",
|
38 |
+
"clean_up_tokenization_spaces": true,
|
39 |
+
"eos_token": "</LongCaption>",
|
40 |
+
"model_max_length": 1024,
|
41 |
+
"pad_token": "<PAD>",
|
42 |
+
"tokenizer_class": "GPT2Tokenizer",
|
43 |
+
"unk_token": "<|endoftext|>"
|
44 |
+
}
|
checkpoint-15000/trainer_state.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
checkpoint-15000/training_args.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:d966d8425fcd55b317e293394041be36b2ae7882096bdd70cf0ca1695a8d60ec
|
3 |
+
size 5304
|
checkpoint-15000/vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
index.html
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<main>
|
2 |
+
<section id="T2I Prompt Generatpr">
|
3 |
+
<h2>Text generation using Flan T5</h2>
|
4 |
+
<form class="text-gen-form">
|
5 |
+
<label for="text-gen-input">Text prompt</label>
|
6 |
+
<input
|
7 |
+
id="text-gen-input"
|
8 |
+
type="text"
|
9 |
+
value="German: There are many ducks"
|
10 |
+
/>
|
11 |
+
<button id="text-gen-submit">Submit</button>
|
12 |
+
<p class="text-gen-output"></p>
|
13 |
+
</form>
|
14 |
+
</section>
|
15 |
+
</main>
|
model.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
+
from vllm import LLM, SamplingParams
|
4 |
+
import logging
|
5 |
+
|
6 |
+
# Configure logging
|
7 |
+
logging.basicConfig(
|
8 |
+
level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
9 |
+
)
|
10 |
+
logger = logging.getLogger(__name__)
|
11 |
+
|
12 |
+
|
13 |
+
class ChallengePromptGenerator:
|
14 |
+
def __init__(
|
15 |
+
self,
|
16 |
+
model_local_dir="checkpoint-15000",
|
17 |
+
):
|
18 |
+
self.generator = LLM(
|
19 |
+
model_local_dir,
|
20 |
+
dtype="bfloat16",
|
21 |
+
)
|
22 |
+
|
23 |
+
|
24 |
+
def infer_prompt(
|
25 |
+
self,
|
26 |
+
prompts,
|
27 |
+
max_generation_length=77,
|
28 |
+
beam_size=1,
|
29 |
+
sampling_temperature=0.9,
|
30 |
+
sampling_topk=1,
|
31 |
+
sampling_topp=1,
|
32 |
+
):
|
33 |
+
added_prompts = [f"{self.generator.get_tokenizer().bos_token} {prompt}" for prompt in prompts]
|
34 |
+
|
35 |
+
sampling_params = SamplingParams(
|
36 |
+
max_tokens=max_generation_length,
|
37 |
+
temperature=sampling_temperature,
|
38 |
+
top_k=sampling_topk,
|
39 |
+
top_p=sampling_topp,
|
40 |
+
use_beam_search=(beam_size > 1),
|
41 |
+
)
|
42 |
+
|
43 |
+
outputs = self.generator.generate(added_prompts, sampling_params)
|
44 |
+
out = []
|
45 |
+
for i in range(len(outputs)):
|
46 |
+
tmp_out = prompts[i] + outputs[i].outputs[0].text
|
47 |
+
if tmp_out[-1] != ".":
|
48 |
+
tmp_out = ".".join(tmp_out.split(".")[:-1]) + "."
|
49 |
+
out.append(tmp_out)
|
50 |
+
return out
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn
|
3 |
+
pydantic
|
start_vllm.sh
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
python app.py --port 8000
|
vllm
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
Subproject commit daed30c4a917c870f8fbddf45e3b027710c0842b
|