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

Feat/dialogpt ru #97

Merged
merged 77 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
72842e3
Fix requirements.txt (#84)
AndriiHura Jan 24, 2022
3e4e9dc
feat: initialize dialogpt_RU
dilyararimovna Feb 15, 2022
f9a92d4
feat: files init
dilyararimovna Feb 15, 2022
2f3159d
feat: basic integration of dialogpt_RU
dilyararimovna Feb 15, 2022
08a0fac
fix: rename dialogpt
dilyararimovna Feb 15, 2022
58a495d
fix: dialogpt to device
dilyararimovna Feb 15, 2022
ac38cd2
fix: dialogpt final version
dilyararimovna Feb 15, 2022
62b5055
fix: dialogpt test
dilyararimovna Feb 15, 2022
83732bf
fix: dialogpt test
dilyararimovna Feb 15, 2022
16205a4
fix: dialogpt resources consumption
dilyararimovna Feb 15, 2022
a9b92a0
fix: dialogpt to tests
dilyararimovna Feb 15, 2022
17a1bd9
feat: dff generative skill
dilyararimovna Feb 15, 2022
98880db
feat: dff generative skill
dilyararimovna Feb 15, 2022
31fc4b4
fix: remove extra files
dilyararimovna Feb 15, 2022
2d67abf
fix: input to dialogpt
dilyararimovna Feb 15, 2022
f0ccb54
fix: input to dialogpt
dilyararimovna Feb 15, 2022
5c724b3
fix: logging
dilyararimovna Feb 15, 2022
f933bb9
fix: turn on tests
dilyararimovna Feb 15, 2022
8d47e8b
fix: get dialog from context
dilyararimovna Feb 16, 2022
6ea26d9
fix: get uttrs from context
dilyararimovna Feb 16, 2022
6c02959
fix: geempty uttrs
dilyararimovna Feb 16, 2022
d32998d
fix: return empty resp
dilyararimovna Feb 16, 2022
7cea083
fix: test file
dilyararimovna Feb 16, 2022
449c74e
fix: tests
dilyararimovna Feb 16, 2022
42d30ba
fix: test ratio
dilyararimovna Feb 16, 2022
0dcd43c
add speech_function_* dist
mtalimanchuk Feb 17, 2022
fe9b194
add speech_function_* dist readme
mtalimanchuk Feb 17, 2022
4484fac
added sf_functions
danielkornev Feb 17, 2022
c3e9cd4
fix ports
mtalimanchuk Feb 17, 2022
966478c
Merge remote-tracking branch 'origin/feat/russian_baseline' into feat…
dilyararimovna Feb 17, 2022
c704781
fix:m codestyle
dilyararimovna Feb 17, 2022
2df75a6
fix deployment config
mtalimanchuk Feb 17, 2022
e9384f6
fix: tests for generative skill
dilyararimovna Feb 17, 2022
3b0cf73
fix: codestyle
dilyararimovna Feb 17, 2022
5e413fa
add formatters, fix pipeline
mtalimanchuk Feb 17, 2022
cd16fa9
update speech function * sources
mtalimanchuk Feb 18, 2022
2bd125c
fix: check if dialogpt is ready
dilyararimovna Feb 18, 2022
35760e8
fix: wait services
dilyararimovna Feb 18, 2022
f5ab532
rename book skill
mtalimanchuk Feb 18, 2022
d1e88c3
remove old book skill, update usages
mtalimanchuk Feb 18, 2022
312fbf4
fix readme
mtalimanchuk Feb 18, 2022
f0e59fb
fix codestyle
mtalimanchuk Feb 18, 2022
052a0d0
fix codestyle
mtalimanchuk Feb 18, 2022
964f1ec
fix codestyle
mtalimanchuk Feb 18, 2022
ef04f3b
fix codestyle line length
mtalimanchuk Feb 18, 2022
365f02d
move res_cor.json to shared files
mtalimanchuk Feb 18, 2022
a67e15c
fix itsdangerous requirements
mtalimanchuk Feb 18, 2022
0f8ef0e
pin itsdangerous requirements for all flask==1.1.1 servers
mtalimanchuk Feb 18, 2022
6f0684a
Merge pull request #102 from deepmipt/fix/combined-classification-fla…
mtalimanchuk Feb 18, 2022
ac1bbf8
fix cpu.yml, dockerfiles and test for sfc, sfp
mtalimanchuk Feb 18, 2022
f20b1ee
fix codestyle issues
mtalimanchuk Feb 18, 2022
c34e6a0
blacked with -l 120
mtalimanchuk Feb 18, 2022
e1fd947
Merge pull request #104 from deepmipt/dev
danielkornev Feb 18, 2022
bcd41fb
following Dilya's holy orders
danielkornev Feb 18, 2022
6c5357d
following Dilya's not so holy orders
danielkornev Feb 18, 2022
fc44581
fix formatters
mtalimanchuk Feb 18, 2022
088df78
fix pipeline
mtalimanchuk Feb 18, 2022
3a4d64c
fix pipeline and formatters
mtalimanchuk Feb 18, 2022
2a6582d
Adding timeouts + mapping of book skill
danielkornev Feb 18, 2022
ea5a118
removed old & irrelevant tests
danielkornev Feb 18, 2022
a72eda6
we've set confidence to super level
danielkornev Feb 18, 2022
0520637
feat: midas cls sent tokenize only if needed (#101)
dilyararimovna Feb 19, 2022
d16bf84
Merge pull request #100 from deepmipt/feat/speech-function-dist-book-…
mtalimanchuk Feb 21, 2022
73e6f9f
Merge remote-tracking branch 'origin/dev' into feat/dialogpt_ru
dilyararimovna Feb 21, 2022
92fdae6
fix:
dilyararimovna Feb 21, 2022
b7e8f42
Merge remote-tracking branch 'origin/feat/russian_baseline' into feat…
dilyararimovna Feb 21, 2022
b73e319
Merge remote-tracking branch 'origin/feat/russian_baseline' into feat…
dilyararimovna Feb 22, 2022
37d03c2
Merge remote-tracking branch 'origin/feat/russian_baseline' into feat…
dilyararimovna Feb 24, 2022
bed7cd8
fix: docker reqs
dilyararimovna Feb 24, 2022
e7afd8d
fix: check another container
dilyararimovna Feb 24, 2022
a6bf723
fix: rights for file
dilyararimovna Feb 24, 2022
1c0e56c
fix: coestyle
dilyararimovna Feb 24, 2022
d30a24d
fix: return tests for intent responder
dilyararimovna Feb 28, 2022
65d12c4
fix: revert intent responder
dilyararimovna Feb 28, 2022
edc38b7
fix: review fixes
dilyararimovna Feb 28, 2022
8641ad6
fix: codestyle
dilyararimovna Feb 28, 2022
b8798e4
Merge remote-tracking branch 'origin/feat/russian_baseline' into feat…
dilyararimovna Mar 2, 2022
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ WIKIDATA_DIALOGUE_SERVICE_URL=http://wikidata-dial-service:8092/model
NEWS_API_ANNOTATOR_URL=http://news-api-annotator:8112/respond
WIKI_FACTS_URL=http://wiki-facts:8116/respond
FACT_RANDOM_SERVICE_URL=http://fact-random:8119/respond
DIALOGPT_SERVICE_URL=http://dialogpt:8091/respond
4 changes: 3 additions & 1 deletion assistant_dists/dream_russian/cpu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ services:
entity-detection:
environment:
CUDA_VISIBLE_DEVICES: ""

dialogpt:
environment:
CUDA_VISIBLE_DEVICES: ""
11 changes: 11 additions & 0 deletions assistant_dists/dream_russian/dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,17 @@ services:
- "~/.deeppavlov:/root/.deeppavlov"
ports:
- 8103:8103
dialogpt:
volumes:
- "./services/dialogpt_RU:/src"
ports:
- 8091:8091
dff-generative-skill:
volumes:
- "./skills/dff_generative_skill:/src"
- "./common:/src/common"
ports:
- 8092:8092
dff-template-skill:
volumes:
- "./skills/dff_template_skill:/src"
Expand Down
38 changes: 36 additions & 2 deletions assistant_dists/dream_russian/docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ services:
WAIT_HOSTS: "dff-program-y-skill:8008, sentseg:8011, convers-evaluation-selector:8009,
dff-intent-responder-skill:8012, intent-catcher:8014, badlisted-words:8018,
ner:8021, convert-reddit:8029, personal-info-skill:8030,
spelling-preprocessing:8074, entity-linking:8075, wiki-parser:8077,
dff-friendship-skill:8086, dff-wiki-skill:8111, entity-detection:8103,
spelling-preprocessing:8074, entity-linking:8075, wiki-parser:8077, dff-generative-skill:8092,
dff-friendship-skill:8086, dff-wiki-skill:8111, entity-detection:8103, dialogpt:8091,
dff-template-skill:8120"
WAIT_HOSTS_TIMEOUT: ${WAIT_TIMEOUT:-480}

Expand Down Expand Up @@ -278,6 +278,40 @@ services:
reservations:
memory: 256M

dialogpt:
env_file: [ .env ]
build:
context: ./services/dialogpt_RU/
args:
SERVICE_PORT: 8091
PRETRAINED_MODEL_NAME_OR_PATH: "Grossmend/rudialogpt3_medium_based_on_gpt2"
command: flask run -h 0.0.0.0 -p 8091
environment:
- CUDA_VISIBLE_DEVICES=0
mtalimanchuk marked this conversation as resolved.
Show resolved Hide resolved
- FLASK_APP=server
deploy:
resources:
limits:
memory: 2.5G
reservations:
memory: 2.5G

dff-generative-skill:
env_file: [ .env ]
build:
args:
SERVICE_PORT: 8092
SERVICE_NAME: dff_generative_skill
context: .
dockerfile: ./skills/dff_generative_skill/Dockerfile
command: gunicorn --workers=1 server:app -b 0.0.0.0:8092 --reload
deploy:
resources:
limits:
memory: 128M
reservations:
memory: 128M

dff-template-skill:
env_file: [.env]
build:
Expand Down
13 changes: 13 additions & 0 deletions assistant_dists/dream_russian/pipeline_conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@
],
"state_manager_method": "add_hypothesis"
},
"dff_generative_skill": {
"connector": {
"protocol": "http",
"timeout": 2,
"url": "http://dff-generative-skill:8092/respond"
},
"dialog_formatter": "state_formatters.dp_formatters:dff_generative_skill_formatter",
"response_formatter": "state_formatters.dp_formatters:skill_with_attributes_formatter_service",
"previous_services": [
"skill_selectors"
],
"state_manager_method": "add_hypothesis"
},
"dff_template_skill": {
"connector": {
"protocol": "http",
Expand Down
4 changes: 4 additions & 0 deletions assistant_dists/dream_russian/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ services:
sentseg:
convers-evaluation-selector:
dff-intent-responder-skill:
dff-generative-skill:
intent-catcher:
badlisted-words:
ner:
Expand All @@ -39,5 +40,8 @@ services:
- "~/.deeppavlov:/root/.deeppavlov"
environment:
- CUDA_VISIBLE_DEVICES=8
dialogpt:
environment:
- CUDA_VISIBLE_DEVICES=7
dff-template-skill:
version: '3.7'
4 changes: 4 additions & 0 deletions common/dff/integration/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@ def get_dialog(ctx: Context, actor: Actor) -> dict:
return {} if ctx.validation else ctx.misc["agent"]["dialog"]


def get_human_utterances(ctx: Context, actor: Actor) -> dict:
return {} if ctx.validation else ctx.misc["agent"]["dialog"]["human_utterances"]


def get_last_human_utterance(ctx: Context, actor: Actor) -> dict:
return {} if ctx.validation else ctx.misc["agent"]["dialog"]["human_utterances"][-1]

Expand Down
20 changes: 20 additions & 0 deletions services/dialogpt_RU/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# syntax=docker/dockerfile:experimental

FROM pytorch/pytorch:1.5-cuda10.1-cudnn7-runtime

WORKDIR /src

ARG PRETRAINED_MODEL_NAME_OR_PATH
ENV PRETRAINED_MODEL_NAME_OR_PATH ${PRETRAINED_MODEL_NAME_OR_PATH}
ARG SERVICE_PORT
ENV SERVICE_PORT ${SERVICE_PORT}

COPY ./requirements.txt /src/requirements.txt
RUN pip install -r /src/requirements.txt

COPY . /src

HEALTHCHECK --interval=5s --timeout=90s --retries=3 CMD curl --fail 127.0.0.1:${SERVICE_PORT}/healthcheck || exit 1


CMD gunicorn --workers=1 server:app -b 0.0.0.0:${SERVICE_PORT} --timeout=300
3 changes: 3 additions & 0 deletions services/dialogpt_RU/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
GPU RAM = 1Gb
cpu time = 0.15 sec
gpu time = 0.05 sec
8 changes: 8 additions & 0 deletions services/dialogpt_RU/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
transformers==4.0.1
sentencepiece==0.1.94
flask==1.1.1
gunicorn==19.9.0
requests==2.22.0
sentry-sdk[flask]==0.14.1
healthcheck==1.3.3
itsdangerous==2.0.1
165 changes: 165 additions & 0 deletions services/dialogpt_RU/server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
"""
Source code is https://github.com/Grossmend/DialoGPT/blob/master/src/service/service.py
"""
import logging
import time
import os
from typing import Dict, List

from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
from flask import Flask, request, jsonify
from healthcheck import HealthCheck
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration

sentry_sdk.init(dsn=os.getenv("SENTRY_DSN"), integrations=[FlaskIntegration()])


logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO)
logger = logging.getLogger(__name__)

PRETRAINED_MODEL_NAME_OR_PATH = os.environ.get(
"PRETRAINED_MODEL_NAME_OR_PATH", "Grossmend/rudialogpt3_medium_based_on_gpt2"
)
logger.info(f"PRETRAINED_MODEL_NAME_OR_PATH = {PRETRAINED_MODEL_NAME_OR_PATH}")

cuda = torch.cuda.is_available()
if cuda:
torch.cuda.set_device(0)
device = "cuda"
else:
device = "cpu"

logger.info(f"dialogpt is set to run on {device}")

params_default = {
"max_length": 256,
"no_repeat_ngram_size": 3,
"do_sample": True,
"top_k": 100,
"top_p": 0.9,
"temperature": 0.6,
"num_return_sequences": 3,
"device": device,
"is_always_use_length": True,
"length_generate": "1",
}


class RussianDialogGPT:
def __init__(self, path_model: str):
self.path_model = path_model
self.tokenizer = None
self.model = None
self._load_model()

def _load_model(self):
logger.info(f"dialogpt Loading model: {self.path_model} ...")
self.tokenizer = AutoTokenizer.from_pretrained(self.path_model)
self.model = AutoModelForCausalLM.from_pretrained(self.path_model)

def get_responses(self, inputs: List[Dict], params: Dict) -> List[str]:

params_ = {
"max_length": params.get("max_length", params_default["max_length"]),
"no_repeat_ngram_size": params.get("no_repeat_ngram_size", params_default["no_repeat_ngram_size"]),
"do_sample": params.get("do_sample", params_default["do_sample"]),
"top_k": params.get("top_k", params_default["top_k"]),
"top_p": params.get("top_p", params_default["top_p"]),
"temperature": params.get("temperature", params_default["temperature"]),
"num_return_sequences": params.get("num_return_sequences", params_default["num_return_sequences"]),
"device": params.get("device", params_default["device"]),
"is_always_use_length": params.get("is_always_use_length", params_default["is_always_use_length"]),
"length_generate": params.get("length_generate", params_default["length_generate"]),
}

inputs_text = ""
for input_ in inputs:
if params_["is_always_use_length"]:
length_rep = len(self.tokenizer.encode(input_["text"]))
if length_rep <= 15:
length_param = "1"
elif length_rep <= 50:
length_param = "2"
elif length_rep <= 256:
length_param = "3"
else:
length_param = "-"
else:
length_param = "-"
inputs_text += f"|{input_['speaker']}|{length_param}|{input_['text']}"
inputs_text += f"|1|{params_['length_generate']}|"

inputs_token_ids = self.tokenizer.encode(inputs_text, return_tensors="pt")
inputs_token_ids = inputs_token_ids.cuda() if cuda else inputs

try:
outputs_token_ids = self.model.generate(
inputs_token_ids,
max_length=params_["max_length"],
no_repeat_ngram_size=params_["no_repeat_ngram_size"],
do_sample=params_["do_sample"],
top_k=params_["top_k"],
top_p=params_["top_p"],
temperature=params_["temperature"],
num_return_sequences=params_["num_return_sequences"],
device=params_["device"],
mask_token_id=self.tokenizer.mask_token_id,
eos_token_id=self.tokenizer.eos_token_id,
unk_token_id=self.tokenizer.unk_token_id,
pad_token_id=self.tokenizer.pad_token_id,
)
except Exception as e:
logger.info(f"dialogpt Error generate: {str(e)}")
return ""

outputs = [self.tokenizer.decode(x, skip_special_tokens=True) for x in outputs_token_ids]
outputs = [x.split("|")[-1] for x in outputs]
# outputs contains list of strings of possible hypotheses
return outputs


try:
model = RussianDialogGPT(PRETRAINED_MODEL_NAME_OR_PATH)
model.model.eval()
if cuda:
model.model.cuda()

logger.info("dialogpt model is ready")
except Exception as e:
sentry_sdk.capture_exception(e)
logger.exception(e)
raise e

app = Flask(__name__)
health = HealthCheck(app, "/healthcheck")
logging.getLogger("werkzeug").setLevel("WARNING")


@app.route("/respond", methods=["POST"])
def respond():
st_time = time.time()

dialog_contexts = request.json.get("dialog_contexts", [])
num_return_sequences = request.json.get("num_return_sequences", 3)

try:
batch_generated_responses = []
for context in dialog_contexts:
# context is a list of dicts, each dict contains text and speaker label
# context = [{"text": "utterance text", "speaker": "human"}, ...]
inputs = [{"text": uttr["text"], "speaker": 1 if uttr["speaker"] == "bot" else 0} for uttr in context][-3:]
hypotheses = model.get_responses(inputs, params={"num_return_sequences": num_return_sequences})
logger.info(f"dialogpt hypotheses: {hypotheses}")
batch_generated_responses.append(hypotheses)

except Exception as exc:
logger.exception(exc)
sentry_sdk.capture_exception(exc)
batch_generated_responses = [[]] * len(dialog_contexts)

total_time = time.time() - st_time
logger.info(f"dialogpt exec time: {total_time:.3f}s")

return jsonify({"generated_responses": batch_generated_responses})
23 changes: 23 additions & 0 deletions services/dialogpt_RU/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import requests


def test_respond():
url = "http://0.0.0.0:8091/respond"

dialog_contexts = [
[
{"speaker": "human", "text": "Привет, как день прошел?"},
{"speaker": "bot", "text": "Хорошо, а у тебя как?"},
{"speaker": "human", "text": "Нормально, посоветуй фильм посмотреть"},
]
]

request_data = {"dialog_contexts": dialog_contexts}
result = requests.post(url, json=request_data).json()["generated_responses"][0]

assert len(result) == 3 and len(result[0]) > 0, f"Got\n{result}"
print("Success!")


if __name__ == "__main__":
test_respond()
3 changes: 3 additions & 0 deletions services/dialogpt_RU/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

python test.py
5 changes: 2 additions & 3 deletions services/masked_lm/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
GPU RAM = 1Gb
cpu time = 0.15 sec
gpu time = 0.05 sec
GPU RAM = 2.1 Gb
gpu time = 0.5 sec
29 changes: 29 additions & 0 deletions skills/dff_generative_skill/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
FROM python:3.9.1
# ###################### IMMUTABLE SECTION ######################################
# Do not change anything in this section
WORKDIR /src

COPY common/dff/requirements.txt .
RUN pip install -r requirements.txt

# ###################### CUSTOM SECTION ######################################
# Here you can make changes

ARG SERVICE_NAME
ENV SERVICE_NAME ${SERVICE_NAME}

COPY skills/${SERVICE_NAME}/requirements.txt .
RUN pip install -r requirements.txt
RUN python -m nltk.downloader wordnet

COPY skills/${SERVICE_NAME}/ ./
COPY ./common/ ./common/

ARG SERVICE_PORT
ENV SERVICE_PORT ${SERVICE_PORT}

# wait for a server answer ( INTERVAL + TIMEOUT ) * RETRIES seconds after that change stutus to unhealthy
HEALTHCHECK --interval=5s --timeout=5s --retries=3 CMD curl --fail 127.0.0.1:${SERVICE_PORT}/healthcheck || exit 1


CMD gunicorn --workers=1 server:app -b 0.0.0.0:${SERVICE_PORT}
Loading