2828
2929# BLS Example  
3030
31- In this example  we demonstrate an end-to-end example for
31+ In this section  we demonstrate an end-to-end example for
3232[ BLS] ( ../../README.md#business-logic-scripting-beta )  in Python backend. The
3333[ model repository] ( https://github.com/triton-inference-server/server/blob/main/docs/model_repository.md ) 
34- should contain [ PyTorch] ( ../pytorch ) , [ AddSub] ( ../add_sub ) , and [ BLS] ( ../bls )  models.
35- The [ PyTorch] ( ../pytorch )  and [ AddSub] ( ../add_sub )  models
36- calculate the sum and difference of the ` INPUT0 `  and ` INPUT1 `  and put the
37- results in ` OUTPUT0 `  and ` OUTPUT1 `  respectively. The goal of the BLS model is
38- the same as [ PyTorch] ( ../pytorch )  and [ AddSub] ( ../add_sub )  models but the
39- difference is that the BLS model will not calculate the sum and difference by
40- itself. The BLS model will pass the input tensors to the [ PyTorch] ( ../pytorch ) 
41- or [ AddSub] ( ../add_sub )  models and return the responses of that model as the
42- final response. The additional parameter ` MODEL_NAME `  determines which model
43- will be used for calculating the final outputs.
34+ should contain [ pytorch] ( ../pytorch ) , [ addsub] ( ../add_sub ) .  The
35+ [ pytorch] ( ../pytorch )  and [ addsub] ( ../add_sub )  models calculate the sum and
36+ difference of the ` INPUT0 `  and ` INPUT1 `  and put the results in ` OUTPUT0 `  and
37+ ` OUTPUT1 `  respectively. This example is broken into two sections. The first
38+ section demonstrates how to perform synchronous BLS requests and the second
39+ section shows how to execute asynchronous BLS requests.
40+ 
41+ ## Synchronous BLS Requests  
42+ 
43+ The goal of sync BLS model is the same as [ pytorch] ( ../pytorch )  and
44+ [ addsub] ( ../add_sub )  models but the difference is that the BLS model will not
45+ calculate the sum and difference by itself. The sync BLS model will pass the
46+ input tensors to the [ pytorch] ( ../pytorch )  or [ addsub] ( ../add_sub )  models and
47+ return the responses of that model as the final response. The additional
48+ parameter ` MODEL_NAME `  determines which model will be used for calculating the
49+ final outputs.
4450
45511 .  Create the model repository:
4652
4753``` console 
4854$ mkdir -p models/add_sub/1 
49- $ mkdir -p models/bls /1 
55+ $ mkdir -p models/bls_sync /1 
5056$ mkdir -p models/pytorch/1 
5157
5258# Copy the Python models 
5359$ cp examples/add_sub/model.py models/add_sub/1/ 
54- $ cp examples/add_sub/config.pbtxt models/add_sub/ 
55- $ cp examples/bls/model .py models/bls /1/ 
56- $ cp examples/bls/config .pbtxt models/bls/  
60+ $ cp examples/add_sub/config.pbtxt models/add_sub/config.pbtxt  
61+ $ cp examples/bls/sync_model .py models/bls_sync /1/model.py  
62+ $ cp examples/bls/sync_config .pbtxt models/bls_sync/config.pbtxt  
5763$ cp examples/pytorch/model.py models/pytorch/1/ 
5864$ cp examples/pytorch/config.pbtxt models/pytorch/ 
5965``` 
@@ -67,7 +73,7 @@ tritonserver --model-repository `pwd`/models
67733 .  Send inference requests to server:
6874
6975``` 
70- python3 examples/bls/client .py 
76+ python3 examples/bls/sync_client .py 
7177``` 
7278
7379You should see an output similar to the output below:
9096  /tmp/python_backend/models/bls/1/model.py(110): execute 
9197``` 
9298
93- The [ bls ] ( ./model .py )  model file is heavily commented with explanations about 
94- each of the function calls.
99+ The [ sync_model.py ] ( ./sync_model .py )  model file is heavily commented with
100+ explanations about  each of the function calls.
95101
96- ## Explanation of the Client Output  
102+ ###  Explanation of the Client Output  
97103
98- The [ client.py] ( ./client .py )  sends three inference requests to the 'bls '
104+ The [ client.py] ( ./sync_client .py )  sends three inference requests to the 'bls_sync '
99105model with different values for the "MODEL_NAME" input. As explained earlier,
100106"MODEL_NAME" determines the model name that the "bls" model will use for
101107calculating the final outputs. In the first request, it will use the "add_sub"
102- model and in the seceond  request it will use the "pytorch" model. The third
108+ model and in the second  request it will use the "pytorch" model. The third
103109request uses an incorrect model name to demonstrate error handling during
104110the inference request execution.
111+ 
112+ ## Asynchronous BLS Requests  
113+ 
114+ In this section we explain how to send multiple BLS requests without waiting for
115+ their response. Asynchronous execution of BLS requests will not block your
116+ model execution and can lead to speedups under certain conditions.
117+ 
118+ The ` bls_async `  model will perform two async BLS requests on the
119+ [ pytorch] ( ../pytorch )  and [ addsub] ( ../add_sub )  models. Then, it will wait until
120+ the inference requests on these models is completed. It will extract ` OUTPUT0 ` 
121+ from the [ pytorch] ( ../pytorch )  and ` OUTPUT1 `  from the [ addsub] ( ../add_sub )  model
122+ to construct the final inference response object using these tensors.
123+ 
124+ 1 .  Create the model repository:
125+ 
126+ ``` console 
127+ $ mkdir -p models/add_sub/1 
128+ $ mkdir -p models/bls_async/1 
129+ $ mkdir -p models/pytorch/1 
130+ 
131+ # Copy the Python models 
132+ $ cp examples/add_sub/model.py models/add_sub/1/ 
133+ $ cp examples/add_sub/config.pbtxt models/add_sub/ 
134+ $ cp examples/bls/async_model.py models/bls_async/1/model.py 
135+ $ cp examples/bls/async_config.pbtxt models/bls_async/config.pbtxt 
136+ $ cp examples/pytorch/model.py models/pytorch/1/ 
137+ $ cp examples/pytorch/config.pbtxt models/pytorch/ 
138+ ``` 
139+ 
140+ 2 .  Start the tritonserver:
141+ 
142+ ``` 
143+ tritonserver --model-repository `pwd`/models 
144+ ``` 
145+ 
146+ 3 .  Send inference requests to server:
147+ 
148+ ``` 
149+ python3 examples/bls/async_client.py 
150+ ``` 
151+ 
152+ You should see an output similar to the output below:
153+ 
154+ ``` 
155+ INPUT0 ([0.72394824 0.45873794 0.4307444  0.07681174]) + INPUT1 ([0.34224355 0.8271524  0.5831284  0.904624  ]) = OUTPUT0 ([1.0661918 1.2858903 1.0138729 0.9814357]) 
156+ INPUT0 ([0.72394824 0.45873794 0.4307444  0.07681174]) - INPUT1 ([0.34224355 0.8271524  0.5831284  0.904624  ]) = OUTPUT1 ([ 0.3817047  -0.36841443 -0.15238398 -0.82781225]) 
157+ ``` 
0 commit comments