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

[pull] master from CogStack:master #19

Merged
merged 8 commits into from
Jun 8, 2024
Merged
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
9 changes: 9 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,15 @@ services:
- "5555:5000"
networks:
- cognet

# uncomment this only when you have gpu access
#deploy:
# resources:
# reservations:
# devices:
# - driver: nvidia
# device_ids: ['0']
# capabilities: ["gpu", "utility", "compute", "video"]

networks:
cognet:
Expand Down
10 changes: 7 additions & 3 deletions envs/env_app
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ APP_MEDCAT_MODEL_PACK=
# APP_MODEL_CUI_FILTER_PATH=/cat/models/cui_filter.txt

# NLP processing
APP_BULK_NPROC=16
APP_BULK_NPROC=8
APP_TRAINING_MODE=False

# Flask server config
SERVER_HOST=0.0.0.0
SERVER_PORT=5000
SERVER_WORKERS=1
SERVER_WORKER_TIMEOUT=300
SERVER_THREADS=16
SERVER_THREADS=1

# set the number of torch threads, this should be used ONLY if you are using CPUs and the default image
# set to -1 or 0 if you are using GPU
APP_TORCH_THREADS=8

# GPU SETTING
# CAUTION, use only if you are using the GPU docker image.
APP_TORCH_THREADS=0
APP_CUDA_DEVICE_COUNT=1
31 changes: 6 additions & 25 deletions medcat_service/nlp_processor/medcat_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def process_content(self, content):
if self.DEID_MODE:
entities = self.cat.get_entities(text)["entities"]
text = self.cat.deid_text(text, redact=self.DEID_REDACT)
else:
else:
if text is not None and len(text.strip()) > 0:
entities = self.cat.get_entities(text)
else:
Expand Down Expand Up @@ -164,24 +164,6 @@ def process_content_bulk(self, content):
:return: processing result containing documents with extracted annotations, stored as KVPs.
"""

# process at least 10 docs per thread and don't bother with starting
# additional threads when less documents were provided
min_doc_per_thread = 10
num_slices = max(1, int(len(content) / min_doc_per_thread))

batch_size = min(300, num_slices)

if batch_size >= self.bulk_nproc:
nproc = self.bulk_nproc
else:
batch_size = min_doc_per_thread
nproc = max(1, num_slices)
if len(content) > batch_size * nproc:
nproc += 1

self.log.debug("NPROC:" + str(nproc))
self.log.debug("Batch size:" + str(batch_size))

# use generators both to provide input documents and to provide resulting annotations
# to avoid too many mem-copies
invalid_doc_ids = []
Expand All @@ -195,10 +177,9 @@ def process_content_bulk(self, content):
for text_record in content:
_text_res.append(self.cat.deid_text(text_record["text"], redact=self.DEID_REDACT))
content = [{"text": txt} for txt in _text_res]
self.log
else:
ann_res = self.cat.multiprocessing_batch_docs_size(
MedCatProcessor._generate_input_doc(content, invalid_doc_ids), batch_size=batch_size, nproc=nproc)
ann_res = self.cat.multiprocessing_batch_char_size(
MedCatProcessor._generate_input_doc(content, invalid_doc_ids), nproc=self.bulk_nproc)

except Exception as e:
self.log.error(repr(e))
Expand Down Expand Up @@ -375,9 +356,9 @@ def _generate_result(self, in_documents, annotations, invalid_doc_idx, additiona
out_res.update(additional_info)
elif self.DEID_MODE:
out_res = {"text": in_ct["text"],
"annotations": [],
"success": True,
"timestamp": NlpProcessor._get_timestamp()}
"annotations": [],
"success": True,
"timestamp": NlpProcessor._get_timestamp()}
out_res.update(additional_info)
else:
# Don't fetch an annotation set
Expand Down
12 changes: 6 additions & 6 deletions medcat_service/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Flask==3.0.2
gunicorn==20.1.0
injector==0.20.1
gunicorn==22.0.0
injector==0.21.0
flask-injector==0.15.0
medcat==1.10.2
medcat==1.11.0
setuptools==65.5.1
simplejson==3.17.6
werkzeug==3.0.1
setuptools_rust==1.6.0
simplejson==3.19.2
werkzeug==3.0.3
setuptools_rust==1.9.0
Loading