Comments (6)
Hi @xiaokening , the XRTransformer.predict
is an API for batch inference (e.g. including dataset construction, batching, logging and etc). You can just XRTransformer.predict
on the 100 data with batch_size=1
for an estimation of the realtime inference time. We are planning to enable a realtime inference API for XR-Transformer in later releases. Thanks.
from pecos.
What model (encoder, output space) are you running inference on? Could you provide sample code how you measure the latency?
from pecos.
the encoder is chinese-roberta-wwm-ext,the outspace is 1073 labels。the XR-TRANSFORMER model is embedded in Flask service。the measure method of the online Inference lattency is to send http requeset method-post。the average of the online Inference lattency of 100 instances is about 420ms。the running env that the Flask service is deployed is a docker container which has 8GPU, 16GB memory, 1 V100 GPU.
there is sample code:
import time
start = time.time()
for i, text in enumerate(X_text):
if i >= 100:
break
payload={'text': text}
r = requests.post(url_2, json=payload)
res.append(r.json()["result"])
(time.time() - start) * 1000 / 100
there is another puzzling question。the average of the online Inference lattency of 100 instances is about 306ms using only CPU ! That's why ?
from pecos.
Could you also look at the inference time on your local GPU machine (without http request)?
from pecos.
Sorry, I don't have a a local GPU machine, I can test the online Inference lattency of XR-TRANSFORMER in a docker conotainer(I think the effect is the same as in a local GPU machine) based on k8s。
there is sample code:
import time
def predict(text):
"""
Use the XR-Transformer model to predict on single text,and the predict time of single instance.
args:
text(str): the input text to predict on.
return:
pred_csr:instance to label prediction (csr_matrix, 1 * nr_labels).
pred_time:the predict time of instance (unit: ms).
"""
tokenized_text = ' '.join(HanLP(text))
x = vectorizer.transform([tokenized_text])
tfidf_x = tfidf_transformer.transform(x)
tfidf_x.sort_indices()
start_time = time.time()
P_matrix = xtf.predict([text],X_feat=tfidf_x,use_gpu=True)
pred_time = (time.time() - start_time) * 1000
return P_matrix, pred_time
def test_online_inference_latency(corpus, n):
"""
test the average online inference latency of XR-TRANSFORMER.
args:
corpus(List(str)):instance text list to predict on.
n:num of ins for predict.
return:
average_time:the average online inference latency of sing instance.
"""
total_time = 0
for i, text in enumerate(corpus):
if i == 0:
_, _ = predict(text) # the first instance used for initializing XR-TRANSFORMER(copy to GPU)
continue
if i <= n:
_, tmp = predict(text)
total_time += tmp
else:
break
return total_time / n
test_online_inference_latency(X_text, 100)
the average of the online Inference lattency of 100 instances is about 402ms.
from pecos.
Thanks! I have solved this @problem。@jiong-zhang
from pecos.
Related Issues (20)
- Prepare training data HOT 1
- Pecos on customized datasets HOT 6
- Is there at least one example showing how to use Pecos from a plain text dataset? HOT 4
- How to get the predicted labels as plain text? HOT 1
- How to set parameters in XR-Transformer training? HOT 1
- XR-Transformer prediction step HOT 2
- Parameter confusion HOT 1
- Decouple transformer vectorisers from sklearn-based ones HOT 2
- Why use tf-idf, not extract through bert?
- Libpecos on Ubuntu 22.04 with Python 3.10 HOT 2
- Pecos killed on ranker training step HOT 4
- XR-transformer model hyperparameters setting HOT 1
- XTransformer model can't be trained it always shows cuda out of memory HOT 9
- MasOS support HOT 1
- How to get "pseudo_pos_tfidf.json" of stage 2 in MACLR HOT 1
- Can't reproduce XR-Transformer Neurips results HOT 2
- libpecos_float32 library cannot be found in Colab platform HOT 1
- ScipyCsrF32 Issue HOT 2
- A problem when using the pecos model to train xtransformer HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pecos.