Allow selection of different TPU device
Allows one to choose TPU device, if multiple are available. I needed this for launching multiple docker containers with Coral Dual Edge TPU with two cores. Without modification, second container raises error, because both are trying to access the first core
π οΈ PR Summary
Made with β€οΈ by Ultralytics Actions
π Summary
Allows one to choose TPU device
This PR improves code readability by refactoring and restructuring the autobackend.py file.
π Key Changes
- Allows one to choose TPU device
- Reformatted and reorganized code for enhanced clarity.
- Added detailed comments to improve code understanding.
- Managed imports for smoother readability.
π― Purpose & Impact
- Improved Readability: The changes make the code easier to read and maintain, benefiting developers.
- Functional Changes: This update allows users to choose TPU device.
π οΈ PR Summary
Made with β€οΈ by Ultralytics Actions
π Summary
Improved guides and backend support for running Coral Edge TPU models on Raspberry Pi with better TPU management.
π Key Changes
- Updated documentation for exporting and running models on Coral Edge TPU.
- Enhanced TPU library handling and version checks in the backend.
- Improved code formatting for better readability and maintenance.
π― Purpose & Impact
- User Guidance: Clarifies steps for setting up Coral Edge TPU with Raspberry Pi, ensuring smoother installation and usage.
- Performance Enhancement: Allows selecting multiple TPUs for inference, optimizing resource usage.
- Code Quality: Improved readability and maintainability of backend code, contributing to easier future updates.
All Contributors have signed the CLA. β
Posted by the CLA Assistant Lite bot.
I have read the CLA Document and I sign the CLA
π Hello @lalayants, thank you for submitting an ultralytics/ultralytics π PR! This is an automated response, and an Ultralytics engineer will assist you soon.
To ensure a seamless integration of your work, please review the following checklist:
- β Define a Purpose: Clearly explain the purpose in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
- β
Synchronize with Source: Confirm your PR is synchronized with the
ultralytics/ultralyticsmainbranch. If it's behind, update it using the 'Update branch' button or by runninggit pullandgit merge mainlocally. - β Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
- β Update Documentation: Update relevant documentation for any new or modified features.
- β Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
- β Sign the CLA: Please ensure you have signed our Contributor License Agreement by writing "I have read the CLA Document and I sign the CLA" in a new message.
- β Minimize Changes: Focus your changes on the minimum necessary for your addition. "It is not daily increase but daily decrease, hack away the unessential." β Bruce Lee
For bug reports, if applicable, please provide a minimum reproducible example (MRE).
For more guidance, please refer to our Contributing Guide. Donβt hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! π
Codecov Report
Attention: Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
Project coverage is 72.09%. Comparing base (
ccda7ff) to head (a95055c). Report is 1 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| ultralytics/nn/autobackend.py | 0.00% | 3 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #16576 +/- ##
==========================================
- Coverage 72.11% 72.09% -0.02%
==========================================
Files 126 126
Lines 16506 16507 +1
==========================================
- Hits 11903 11901 -2
- Misses 4603 4606 +3
| Flag | Coverage Ξ | |
|---|---|---|
| Benchmarks | 35.43% <40.00%> (-0.01%) |
:arrow_down: |
| GPU | 29.63% <40.00%> (-0.01%) |
:arrow_down: |
| Tests | 68.57% <40.00%> (-0.02%) |
:arrow_down: |
Flags with carried forward coverage won't be shown. Click here to find out more.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Do you have a code example how someone would actually use this to select a different tpu?
Do you have a code example how someone would actually use this to select a different tpu?
Yeah, below is an example of docker-compose setup. As you can see, you just need to add environment variable TPU_DEVICE. For non-docker usage, just setup it any preferable way.
services:
yolo_1:
build:
context: .
image: image_name
container_name: yolo_1
command: [ "/bin/bash", "-ci", "python3 yolo_test/v8_tpu.py" ]
ipc: host
stdin_open: true
tty: true
restart: always
network_mode: host
working_dir: /workspace/
privileged: true
volumes:
- /etc/localtime:/etc/localtime:ro
- ./yolo_test:/workspace/yolo_test
environment:
TPU_DEVICE: ":0"
yolo_2:
image: image_name
container_name: yolo_2
command: [ "/bin/bash", "-ci", "python3 yolo_test/v8_tpu.py" ]
ipc: host
stdin_open: true
tty: true
restart: always
network_mode: host
working_dir: /workspace/
privileged: true
volumes:
- /etc/localtime:/etc/localtime:ro
- ./yolo_test:/workspace/yolo_test
environment:
TPU_DEVICE: ":1"
@lalayants I've updated the relevant documentation for your changes.
The device selection now uses the device argument instead of setting a environment variable, which should be much more convenient to use.
@Laughing-q this is ready for review.
@lalayants @Skillnoob I noticed besides the actual changes this PR are making there are a lot code format updates, for example:
Can we revert that?
Yeah, the code formats can be reverted, they weren't done by me. I'm able to do that in a few hours when I can get on my pc.
@Laughing-q I've removed the unnecessary reformat.
@Skillnoob @lalayants Looks good to me!
@glenn-jocher This is ready to merge
@Skillnoob @Laughing-q @lalayants thank you all! PR merged :)