diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index dd09884..9449286 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -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: diff --git a/envs/env_app b/envs/env_app index 322f8ec..ee3a7a3 100644 --- a/envs/env_app +++ b/envs/env_app @@ -23,7 +23,7 @@ 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 @@ -31,8 +31,12 @@ 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 \ No newline at end of file +APP_CUDA_DEVICE_COUNT=1 \ No newline at end of file diff --git a/medcat_service/nlp_processor/medcat_processor.py b/medcat_service/nlp_processor/medcat_processor.py index 6b63eb4..ee5335f 100644 --- a/medcat_service/nlp_processor/medcat_processor.py +++ b/medcat_service/nlp_processor/medcat_processor.py @@ -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: @@ -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 = [] @@ -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)) @@ -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 diff --git a/medcat_service/requirements.txt b/medcat_service/requirements.txt index 54cfd79..cdd508a 100644 --- a/medcat_service/requirements.txt +++ b/medcat_service/requirements.txt @@ -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 \ No newline at end of file +simplejson==3.19.2 +werkzeug==3.0.3 +setuptools_rust==1.9.0 \ No newline at end of file