Created
June 19, 2024 12:51
-
-
Save daniil-lyakhov/e0d024d3a61bfa0052895cffee0fef8e to your computer and use it in GitHub Desktop.
Input difference between Yolov8 and Yolov8 compiled by the `torch.compile`
This file contains 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
# torch==2.3.1 | |
# ultralytics==8.2.35 | |
import torch | |
from ultralytics.models.yolo import YOLO | |
torch.manual_seed(42) | |
def run_yolo(torch_fx, inputs): | |
yolo_model = YOLO("yolov8n") | |
model = yolo_model.model | |
if torch_fx: | |
model = torch.compile(model) | |
return model(inputs)[0] | |
if __name__ == "__main__": | |
inputs = torch.rand((1, 3, 640, 640)) | |
print("Run Torch model...") | |
torch_t = run_yolo(torch_fx=False, inputs=inputs) | |
print("Run Torch FX model...") | |
fx_t = run_yolo(torch_fx=True, inputs=inputs) | |
abs_diff = torch.abs(torch_t - fx_t) | |
idx = torch.argmax(abs_diff) | |
print(f"argmax idx: {idx}") | |
print(f"torch value: {torch_t.view(-1)[idx]}") | |
print(f"torch FX value: {fx_t.view(-1)[idx]}") | |
print(f'abs diff: {abs_diff.view(-1)[idx]}') | |
print(f"torch.quantile(abs_diff, 0.96) {torch.quantile(abs_diff, 0.96)}") |
Author
daniil-lyakhov
commented
Jun 19, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment