Spaces:
Runtime error
Runtime error
phongtran
commited on
Commit
·
00f7d2c
1
Parent(s):
a86b8bb
first
Browse files- Dockerfile +40 -11
- app.py +42 -0
- pre-requirements.txt +3 -0
- requirements.txt +1 -0
Dockerfile
CHANGED
@@ -1,17 +1,46 @@
|
|
1 |
-
FROM
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
WORKDIR /code
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
#
|
11 |
-
|
12 |
-
rstudio/bslib \
|
13 |
-
rstudio/httpuv
|
14 |
|
15 |
-
|
|
|
16 |
|
17 |
-
CMD ["
|
|
|
1 |
+
FROM nvidia/cuda:12.1.1-cudnn8-devel-ubuntu22.04
|
2 |
+
|
3 |
+
ARG DEBIAN_FRONTEND=noninteractive
|
4 |
+
|
5 |
+
ENV PYTHONUNBUFFERED=1
|
6 |
+
|
7 |
+
RUN apt-get update && apt-get install --no-install-recommends -y \
|
8 |
+
build-essential \
|
9 |
+
python3.9 \
|
10 |
+
python3-pip \
|
11 |
+
git \
|
12 |
+
ffmpeg \
|
13 |
+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
|
14 |
|
15 |
WORKDIR /code
|
16 |
|
17 |
+
COPY ./pre-requirements.txt /code/pre-requirements.txt
|
18 |
+
|
19 |
+
COPY ./requirements.txt /code/requirements.txt
|
20 |
+
|
21 |
+
|
22 |
+
# Set up a new user named "user" with user ID 1000
|
23 |
+
RUN useradd -m -u 1000 user
|
24 |
+
# Switch to the "user" user
|
25 |
+
USER user
|
26 |
+
# Set home to the user's home directory
|
27 |
+
ENV HOME=/home/user \
|
28 |
+
PATH=/home/user/.local/bin:$PATH \
|
29 |
+
PYTHONPATH=$HOME/app \
|
30 |
+
PYTHONUNBUFFERED=1 \
|
31 |
+
GRADIO_ALLOW_FLAGGING=never \
|
32 |
+
GRADIO_NUM_PORTS=1 \
|
33 |
+
GRADIO_SERVER_NAME=0.0.0.0 \
|
34 |
+
GRADIO_THEME=huggingface \
|
35 |
+
SYSTEM=spaces
|
36 |
+
|
37 |
+
RUN pip3 install --no-cache-dir --upgrade -r /code/pre-requirements.txt
|
38 |
+
RUN pip3 install --no-cache-dir --upgrade -r /code/requirements.txt
|
39 |
|
40 |
+
# Set the working directory to the user's home directory
|
41 |
+
WORKDIR $HOME/app
|
|
|
|
|
42 |
|
43 |
+
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
44 |
+
COPY --chown=user . $HOME/app
|
45 |
|
46 |
+
CMD ["python3", "app.py"]
|
app.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoConfig, AutoModelForCausalLM, AutoTokenizer
|
3 |
+
import torch
|
4 |
+
import os
|
5 |
+
|
6 |
+
model_path = "vinai/PhoGPT-7B5-Instruct"
|
7 |
+
|
8 |
+
config = AutoConfig.from_pretrained(model_path, trust_remote_code=True, token=os.environ['HK_TOKEN'])
|
9 |
+
config.init_device = "cuda"
|
10 |
+
# config.attn_config['attn_impl'] = 'triton' # Enable if "triton" installed!
|
11 |
+
|
12 |
+
model = AutoModelForCausalLM.from_pretrained(
|
13 |
+
model_path, config=config, torch_dtype=torch.bfloat16, trust_remote_code=True, token=os.environ['HK_TOKEN']
|
14 |
+
)
|
15 |
+
# If your GPU does not support bfloat16:
|
16 |
+
# model = AutoModelForCausalLM.from_pretrained(model_path, config=config, torch_dtype=torch.float16, trust_remote_code=True)
|
17 |
+
model.eval()
|
18 |
+
|
19 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True, token=os.environ['HK_TOKEN'])
|
20 |
+
|
21 |
+
|
22 |
+
def answer(input_prompt):
|
23 |
+
input_ids = tokenizer(input_prompt, return_tensors="pt")
|
24 |
+
|
25 |
+
outputs = model.generate(
|
26 |
+
inputs=input_ids["input_ids"].to("cuda"),
|
27 |
+
attention_mask=input_ids["attention_mask"].to("cuda"),
|
28 |
+
do_sample=True,
|
29 |
+
temperature=1.0,
|
30 |
+
top_k=50,
|
31 |
+
top_p=0.9,
|
32 |
+
max_new_tokens=1024,
|
33 |
+
eos_token_id=tokenizer.eos_token_id,
|
34 |
+
pad_token_id=tokenizer.pad_token_id
|
35 |
+
)
|
36 |
+
|
37 |
+
response = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
38 |
+
response = response.split("### Trả lời:")[1]
|
39 |
+
return response
|
40 |
+
|
41 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
42 |
+
iface.launch()
|
pre-requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
transformers
|
3 |
+
torch
|
requirements.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
einops
|