Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mdx で試した時の問題に対する修正 #3

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docker_sample/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ RUN apt-get update && \
&& rm -rf /var/lib/apt/lists/*

# vLLMのインストール
RUN pip install --no-cache-dir vllm
RUN pip install --no-cache-dir vllm nvidia-ml-py && \
pip uninstall --yes pynvml && \
pip install -U --no-cache-dir opencv-python-headless==4.5.5.62

# モデルファイルをイメージに取り込む (FIXME: モデルファイルのパスを変更)
COPY ./models/llm-jp/llm-jp-3-1.8b-instruct /workspace/model
Expand Down
1 change: 0 additions & 1 deletion docker_sample/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ sudo docker load < [チームID].tar

```bash
docker run --rm \
--runtime=nvidia \
--gpus all \
--network none \
-v "$(pwd)/data:/data" \
Expand Down
8 changes: 5 additions & 3 deletions docker_sample/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import argparse
from vllm import LLM

# see more examples at https://github.com/vllm-project/vllm/tree/main/examples
chat_template = "{{ (messages|selectattr('role', 'equalto', 'system')|list|last).content|trim if (messages|selectattr('role', 'equalto', 'system')|list) else '' }}\n\n{% for message in messages %}\n{% if message['role'] == 'user' %}\n{{ message['content']|trim -}}\n{% if not loop.last %}\n\n\n{% endif %}\n{% elif message['role'] == 'assistant' %}\n{{ message['content']|trim -}}\n{% if not loop.last %}\n\n\n{% endif %}\n{% elif message['role'] == 'user_context' %}\n{{ message['content']|trim -}}\n{% if not loop.last %}\n\n\n{% endif %}\n{% endif %}\n{% endfor %}\n"

def main():
parser = argparse.ArgumentParser()
Expand All @@ -26,9 +28,9 @@ def main():
for d in data:
messages_list.append({"role": "user", "content": d["text"]})

outputs = llm.chat(messages_list)
for i, output in enumerate(outputs):
data[i]["response"] = output.outputs[0].text
for i, m in enumerate(messages_list):
output = llm.chat([m], chat_template=chat_template)
data[i]["response"] = output[0].outputs[0].text.strip()

os.makedirs(os.path.dirname(args.output_path), exist_ok=True)
with open(args.output_path, "w", encoding="utf-8") as f:
Expand Down