Skip to content

Instantly share code, notes, and snippets.

View AlexMikhalev's full-sized avatar

Dr Alexander Mikhalev AlexMikhalev

View GitHub Profile
10:M 30 Apr 2021 21:27:20.002 * <rg> GEARS: QA cached called {'event': 'keymiss', 'key': 'cache_{06S}_{PMC261870.xml:{06S}:26}_Laser Correction', 'type': 'empty', 'value': None}
=== REDIS BUG REPORT START: Cut & paste starting from here ===
10:M 30 Apr 2021 21:27:20.002 # === ASSERTION FAILED ===
10:M 30 Apr 2021 21:27:20.002 # ==> module.c:4085 '(c->flags & CLIENT_BLOCKED) == 0' is not true
------ STACK TRACE ------
Backtrace:
@AlexMikhalev
AlexMikhalev / mermaid.md
Created April 22, 2021 09:31
Mermaid parse example
graph TD
    A[Christmas] -->|Get money| B(Go shopping)
    B --> C{Let me think}
    C -->|One| D[Laptop]
    C -->|Two| E[iPhone]
    C -->|Three| F[fa:fa-car Car]
@AlexMikhalev
AlexMikhalev / qa_search.py
Created April 19, 2021 19:55
BERT QA on RedisAI inside RedisGears
### This gears will pre-compute (encode) all sentences using BERT tokenizer for QA
tokenizer = None
def loadTokeniser():
global tokenizer
from transformers import BertTokenizerFast
tokenizer = BertTokenizerFast.from_pretrained("bert-large-uncased-whole-word-masking-finetuned-squad")
return tokenizer
@AlexMikhalev
AlexMikhalev / qa_search.py
Created April 17, 2021 22:58
QA bert interim working
tokenizer = None
import numpy as np
import torch
import os
config_switch=os.getenv('DOCKER', 'local')
if config_switch=='local':
startup_nodes = [{"host": "127.0.0.1", "port": "30001"}, {"host": "127.0.0.1", "port":"30002"}, {"host":"127.0.0.1", "port":"30003"}]
else:
@AlexMikhalev
AlexMikhalev / qa_search.py
Last active April 17, 2021 20:06
QA BERT pre-cashed
tokenizer = None
import numpy as np
import torch
import os
config_switch=os.getenv('DOCKER', 'local')
if config_switch=='local':
startup_nodes = [{"host": "127.0.0.1", "port": "30001"}, {"host": "127.0.0.1", "port":"30002"}, {"host":"127.0.0.1", "port":"30003"}]
else:
@AlexMikhalev
AlexMikhalev / memory.py
Created April 8, 2021 13:40
Check memory usage in python
#standard module
# peak memory usage (kilobytes on Linux, bytes on OS X)
import resource
resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
# pip install psutil
import os, psutil; print(psutil.Process(os.getpid()).memory_info().rss / 1024 ** 2)

Problem

When I use docker to work with the shared workspace with host under Ubuntu, I find that files created by docker user is owned by root. This is not the same with macOS.

Maybe this is becuase docker is run by root user and the default user mapping mechanism is to map container-root to host-user or host-root. So can I map the container-root or container-any-user to host-current-user?

Fortunately the latest docker supports the re-map the container user to any host user via Linux namespace. Refer to this.

Linux namespace

```
redis-cli -c -p 30001 -h 127.0.0.1
127.0.0.1:30001> keys *
1) "processed_docs_stage1_para"
2) "sentence:PMC293432.xml:{06S}"
3) "sentence:PMC270701.xml:{06S}"
4) "edges_matched_{06S}"
5) "sentence:PMC222961.xml:{06S}"
6) "processed_docs_stage3{06S}"
7) "processed_docs_stage2_para{06S}"
from transformers import AutoTokenizer, AutoModel
tokenizer = None
def loadTokeniser():
global tokenizer
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("t5-base",torchscript=True)
# Try RobertaTokenizerFast and BART
# tokenizer = AutoTokenizer.from_pretrained("emilyalsentzer/Bio_ClinicalBERT")
return tokenizer
@AlexMikhalev
AlexMikhalev / export_trace.py
Created March 18, 2021 22:53 — forked from lantiga/export_trace.py
🤗 Huggingface Bert on RedisAI
from transformers import BertForQuestionAnswering
import torch
bert_name = "bert-large-uncased-whole-word-masking-finetuned-squad"
model = BertForQuestionAnswering.from_pretrained(bert_name, torchscript=True)
model.eval()
inputs = [torch.ones(1, 2, dtype=torch.int64),
torch.ones(1, 2, dtype=torch.int64),