-
Notifications
You must be signed in to change notification settings - Fork 132
Openvino #228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
iiSeymour
wants to merge
15
commits into
master
Choose a base branch
from
openvino
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Openvino #228
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ebc7792
Intel OpenVINO backend
dkurt d62cb24
Merge pull request #52 from dkurt/openvino
iiSeymour 45a5dd0
full bonito.crf on openvino
iiSeymour cb5e5d8
cpu version in openvino module
iiSeymour 778c85d
full seqdist interface
iiSeymour 3c2d94f
merge master
iiSeymour ca049bb
update to v0.5.1 - merge master
iiSeymour ec54eed
Use OpenVINO 2022 with new API and batching
dkurt 49b4a66
Use batching with OpenVINO
dkurt c59ccec
Merge pull request #238 from dkurt/openvino_2022
iiSeymour a2c9cf9
Revert "Use OpenVINO 2022"
iiSeymour 5046577
Merge pull request #240 from nanoporetech/revert-238-openvino_2022
iiSeymour 69dc45c
Merge pull request #239 from dkurt/openvino_batch
iiSeymour 676fdc5
Use OpenVINO 2022 with new API
dkurt bbedf73
Merge pull request #244 from dkurt/openvino_2022
iiSeymour File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # Bonito | ||
|
|
||
| [](https://badge.fury.io/py/ont-bonito) | ||
| [](https://badge.fury.io/py/ont-bonito) | ||
| [](https://img.shields.io/badge/python-3.7-brightgreen.svg) | ||
| [](https://img.shields.io/badge/python-3.8-brightgreen.svg) | ||
| [](https://img.shields.io/badge/python-3.9-brightgreen.svg) | ||
|
|
@@ -35,6 +35,12 @@ The default `ont-bonito` package is built against CUDA 10.2 however CUDA 11.1 an | |
| $ pip install -f https://download.pytorch.org/whl/torch_stable.html ont-bonito-cuda111 | ||
| ``` | ||
|
|
||
| To optimize inference on CPU with Intel OpenVINO use `--use_openvino` flag: | ||
|
|
||
| ```bash | ||
| $ bonito basecaller dna_r9.4.1 --reference reference.mmi --use_openvino --device=cpu /data/reads > basecalls.sam | ||
| ``` | ||
|
|
||
| ## Modified Bases | ||
|
|
||
| Modified base calling is handled by [Remora](https://github.com/nanoporetech/remora). | ||
|
|
@@ -54,7 +60,7 @@ $ bonito basecaller dna_r9.4.1 --save-ctc --reference reference.mmi /data/reads | |
| $ bonito train --directory /data/training/ctc-data /data/training/model-dir | ||
| ``` | ||
|
|
||
| In addition to training a new model from scratch you can also easily fine tune one of the pretrained models. | ||
| In addition to training a new model from scratch you can also easily fine tune one of the pretrained models. | ||
|
|
||
| ```bash | ||
| bonito train --epochs 1 --lr 5e-4 --pretrained [email protected] --directory /data/training/ctc-data /data/training/fine-tuned-model | ||
|
|
@@ -67,7 +73,7 @@ $ bonito download --training | |
| $ bonito train /data/training/model-dir | ||
| ``` | ||
|
|
||
| All training calls use Automatic Mixed Precision to speed up training. To disable this, set the `--no-amp` flag to True. | ||
| All training calls use Automatic Mixed Precision to speed up training. To disable this, set the `--no-amp` flag to True. | ||
|
|
||
| ## Developer Quickstart | ||
|
|
||
|
|
@@ -81,6 +87,11 @@ $ source venv3/bin/activate | |
| (venv3) $ python setup.py develop | ||
| ``` | ||
|
|
||
| To build with OpenVINO backend: | ||
| ```bash | ||
| (venv3) $ pip install develop .[openvino] | ||
| ``` | ||
|
|
||
| ## Interface | ||
|
|
||
| - `bonito view` - view a model architecture for a given `.toml` file and the number of parameters in the network. | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import torch | ||
| from crf_beam import beam_search | ||
| from bonito.crf.basecall import stitch_results | ||
| from bonito.multiprocessing import thread_iter, thread_map | ||
| from bonito.util import chunk, stitch, batchify, unbatchify | ||
|
|
||
|
|
||
| def compute_scores(model, batch): | ||
| scores = model(batch) | ||
| fwd = model.seqdist.forward_scores(scores) | ||
| bwd = model.seqdist.backward_scores(scores) | ||
| posts = torch.softmax(fwd + bwd, dim=-1) | ||
| return { | ||
| 'scores': scores.transpose(0, 1), | ||
| 'bwd': bwd.transpose(0, 1), | ||
| 'posts': posts.transpose(0, 1), | ||
| } | ||
|
|
||
|
|
||
| def decode(x, beam_width=32, beam_cut=100.0, scale=1.0, offset=0.0, blank_score=2.0): | ||
| sequence, qstring, moves = beam_search(x['scores'], x['bwd'], x['posts']) | ||
| return { | ||
| 'sequence': sequence, | ||
| 'qstring': qstring, | ||
| 'moves': moves, | ||
| } | ||
|
|
||
|
|
||
| def basecall(model, reads, chunksize=4000, overlap=100, batchsize=32, reverse=False): | ||
|
|
||
| chunks = thread_iter( | ||
| ((read, 0, len(read.signal)), chunk(torch.from_numpy(read.signal), chunksize, overlap)) | ||
| for read in reads | ||
| ) | ||
|
|
||
| batches = thread_iter(batchify(chunks, batchsize=batchsize)) | ||
|
|
||
| scores = thread_iter( | ||
| (read, compute_scores(model, batch)) for read, batch in batches | ||
| ) | ||
|
|
||
| results = thread_iter( | ||
| (read, stitch_results(scores, end - start, chunksize, overlap, model.stride)) | ||
| for ((read, start, end), scores) in unbatchify(scores) | ||
| ) | ||
|
|
||
| return thread_map(decode, results, n_thread=48) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.