|
1 | | -# Project |
| 1 | +# Batch Inference Toolkit |
2 | 2 |
|
3 | | -> This repo has been populated by an initial template to help get you started. Please |
4 | | -> make sure to update the content to build a great experience for community-building. |
| 3 | +Batch Inference Toolkit(batch-inference) is a Python package that batches model input tensors coming from multiple users dynamically, executes the model, un-batches output tensors and then returns them back to each user respectively. This will improve system throughput because of a better cache locality. The entire process is transparent to developers. |
5 | 4 |
|
6 | | -As the maintainer of this project, please make a few updates: |
| 5 | +## Installation |
7 | 6 |
|
8 | | -- Improving this README.MD file to provide a great experience |
9 | | -- Updating SUPPORT.MD with content about this project's support experience |
10 | | -- Understanding the security reporting process in SECURITY.MD |
11 | | -- Remove this section from the README |
| 7 | +**Install from Pip** _(Coming Soon)_ |
12 | 8 |
|
13 | | -## Contributing |
| 9 | +```bash |
| 10 | +python -m pip install batch-inference --upgrade |
| 11 | +``` |
14 | 12 |
|
15 | | -This project welcomes contributions and suggestions. Most contributions require you to agree to a |
16 | | -Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us |
17 | | -the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com. |
| 13 | +**Build and Install from Source** _(for developers)_ |
18 | 14 |
|
19 | | -When you submit a pull request, a CLA bot will automatically determine whether you need to provide |
20 | | -a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions |
21 | | -provided by the bot. You will only need to do this once across all repos using our CLA. |
| 15 | +```bash |
| 16 | +git clone https://github.com/microsoft/batch-inference.git |
| 17 | +python -m pip install -e .[docs,testing] |
22 | 18 |
|
23 | | -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). |
24 | | -For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or |
25 | | -contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. |
| 19 | +# if you want to format the code before commit |
| 20 | +pip install pre-commit |
| 21 | +pre-commit install |
26 | 22 |
|
27 | | -## Trademarks |
| 23 | +# run unittests |
| 24 | +python -m unittest discover tests |
| 25 | +``` |
28 | 26 |
|
29 | | -This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft |
30 | | -trademarks or logos is subject to and must follow |
31 | | -[Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general). |
32 | | -Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. |
33 | | -Any use of third-party trademarks or logos are subject to those third-party's policies. |
| 27 | +## Example |
| 28 | + |
| 29 | +```python |
| 30 | +import threading |
| 31 | +import numpy as np |
| 32 | +from batch_inference import batching |
| 33 | + |
| 34 | + |
| 35 | +@batching(max_batch_size=32) |
| 36 | +class MyModel: |
| 37 | + def __init__(self, k, n): |
| 38 | + self.weights = np.random.randn((k, n)).astype("f") |
| 39 | + |
| 40 | + # x: [batch_size, m, k], self.weights: [k, n] |
| 41 | + def predict_batch(self, x): |
| 42 | + y = np.matmul(x, self.weights) |
| 43 | + return y |
| 44 | + |
| 45 | + |
| 46 | +with MyModel.host(3, 3) as host: |
| 47 | + def send_requests(): |
| 48 | + for _ in range(0, 10): |
| 49 | + x = np.random.randn(1, 3, 3).astype("f") |
| 50 | + y = host.predict(x) |
| 51 | + |
| 52 | + threads = [threading.Thread(target=send_requests) for i in range(0, 32)] |
| 53 | + [th.start() for th in threads] |
| 54 | + [th.join() for th in threads] |
| 55 | + |
| 56 | +``` |
| 57 | + |
| 58 | +## Build the Docs |
| 59 | + |
| 60 | +Run the following commands and open `docs/_build/html/index.html` in browser. |
| 61 | + |
| 62 | +```bash |
| 63 | +pip install sphinx myst-parser sphinx-rtd-theme sphinxemoji |
| 64 | +cd docs/ |
| 65 | + |
| 66 | +make html # for linux |
| 67 | +.\make.bat html # for windows |
| 68 | +``` |
0 commit comments