-
Notifications
You must be signed in to change notification settings - Fork 91
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
PTQ with ResNet conv2x layers #1433
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit
black
programming_examples/ml/resnet/ptq_conv2x/test.py|390|
programming_examples/ml/resnet/ptq_conv2x/test.py|399|
programming_examples/ml/resnet/ptq_conv2x/test.py|403|
programming_examples/ml/resnet/ptq_conv2x/test.py|405|
programming_examples/ml/resnet/ptq_conv2x/test.py|446|
programming_examples/ml/resnet/ptq_conv2x/test.py|449|
programming_examples/ml/resnet/ptq_conv2x/test.py|459|
programming_examples/ml/resnet/ptq_conv2x/test.py|465 col 1|
programming_examples/ml/resnet/ptq_conv2x/utils.py|5 col 1|
programming_examples/ml/resnet/ptq_conv2x/utils.py|40|
|
||
@core(cores[i][1], "conv2dk3.o") | ||
def core_body(): | ||
if(i==2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
if(i==2): | |
if i == 2: |
|
||
@core(cores[i][3], "conv2dk3.o") | ||
def core_body(): | ||
if(i==2): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
if(i==2): | |
if i == 2: |
NpuWriteRTPOp("rtpComputeTile12", col=1, row=2, index=0, value=9) | ||
NpuWriteRTPOp("rtpComputeTile13", col=1, row=3, index=0, value=12) | ||
NpuWriteRTPOp("rtpComputeTile13", col=1, row=3, index=1, value=0) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
|
||
NpuWriteRTPOp("rtpComputeTile22", col=2, row=2, index=0, value=9) | ||
NpuWriteRTPOp("rtpComputeTile23", col=2, row=3, index=0, value=9) | ||
NpuWriteRTPOp("rtpComputeTile25", col=2, row=5, index=0, value=9) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
NpuWriteRTPOp("rtpComputeTile25", col=2, row=5, index=0, value=9) | |
NpuWriteRTPOp("rtpComputeTile25", col=2, row=5, index=0, value=9) |
rtp_1=[7,10,13,-2,10] | ||
rtp_2=[8,10,12] | ||
rtp_3=[9,9,12] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
rtp_1=[7,10,13,-2,10] | |
rtp_2=[8,10,12] | |
rtp_3=[9,9,12] | |
rtp_1 = [7, 10, 13, -2, 10] | |
rtp_2 = [8, 10, 12] | |
rtp_3 = [9, 9, 12] |
block_0_relu_2 * block_0_weight_scale_3 / block_0_add_scale, 2 | ||
) # after conv1x1 | ||
block_0_combined_scale4 = -math.log( | ||
block_0_add_scale / block_0_relu_3, 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
block_0_add_scale / block_0_relu_3, 2 | |
block_0_add_scale / block_0_relu_3, 2 |
) # after skip addition using init scale | ||
# combined_scale4=-math.log(inp_scale1/inp_scale4) | ||
block_0_combined_scale_skip = -math.log( | ||
init_scale * block_0_weight_scale_skip / block_0_add_scale, 2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
init_scale * block_0_weight_scale_skip / block_0_add_scale, 2 | |
init_scale * block_0_weight_scale_skip / block_0_add_scale, 2 |
print("Block0 combined_scale after first conv1x1:", block_0_combined_scale1) | ||
print("Block0 combined_scale after second conv3x3:", block_0_combined_scale2) | ||
print("Block0 combined_scale after third conv1x1:", block_0_combined_scale3) | ||
print("Block0 combined_scale after adding skip connection:", (block_0_combined_scale4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
print("Block0 combined_scale after adding skip connection:", (block_0_combined_scale4)) | |
print( | |
"Block0 combined_scale after adding skip connection:", (block_0_combined_scale4) | |
) |
print("Block1 combined_scale after first conv1x1:", block_1_combined_scale1) | ||
print("Block1 combined_scale after second conv3x3:", block_1_combined_scale2) | ||
print("Block1 combined_scale after third conv1x1:", block_1_combined_scale3) | ||
print("Block1 combined_scale after adding skip connection:", (block_1_combined_scale4)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
print("Block1 combined_scale after adding skip connection:", (block_1_combined_scale4)) | |
print( | |
"Block1 combined_scale after adding skip connection:", (block_1_combined_scale4) | |
) |
(block_2_combined_scale4), | ||
) | ||
print("------------------------------------------------------------------") | ||
# ------------------------------------------------------ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
# ------------------------------------------------------ | |
# ------------------------------------------------------ |
c1993b0
to
dacdc6a
Compare
im_name = f"./cifar_images/image_{i}.png" | ||
cv2.imwrite(im_name, im) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
) | ||
quant_id_1.eval() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
# ------------------------------------------------------ | ||
# Main run loop | ||
# ------------------------------------------------------ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
# ------------------------------------------------------ | ||
|
||
for i in range(0, 64): | ||
print("____________________________________IMAGE {}____________________________________________".format(i)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
print("____________________________________IMAGE {}____________________________________________".format(i)) | |
print( | |
"____________________________________IMAGE {}____________________________________________".format( | |
i | |
) | |
) |
|
||
# Calculate the five categories with the highest classification probability | ||
prediction_class_index = ( | ||
torch.topk(final_output_aie, k=5, sorted=True).indices.squeeze(0).tolist() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
torch.topk(final_output_aie, k=5, sorted=True).indices.squeeze(0).tolist() | |
torch.topk(final_output_aie, k=5, sorted=True) | |
.indices.squeeze(0) | |
.tolist() |
torch.topk(final_output_aie, k=5, sorted=True).indices.squeeze(0).tolist() | ||
) | ||
golden_prediction_class_index = ( | ||
torch.topk(final_output_base, k=5, sorted=True).indices.squeeze(0).tolist() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
torch.topk(final_output_base, k=5, sorted=True).indices.squeeze(0).tolist() | |
torch.topk(final_output_base, k=5, sorted=True) | |
.indices.squeeze(0) | |
.tolist() |
if x != y: | ||
print("\nFailed.\n") | ||
exit(-1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
if x != y: | |
print("\nFailed.\n") | |
exit(-1) | |
if x != y: | |
print("\nFailed.\n") | |
exit(-1) |
print("\nPASS!\n") | ||
exit(0) | ||
|
||
if __name__ == "__main__": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
if __name__ == "__main__": | |
if __name__ == "__main__": |
import cv2 | ||
import numpy as np | ||
|
||
def unpickle(file): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
def unpickle(file): | |
def unpickle(file): |
im = im.transpose(1, 2, 0) | ||
im = cv2.cvtColor(im, cv2.COLOR_RGB2BGR) | ||
im_name = f"./cifar_images/image_{i}.png" | ||
cv2.imwrite(im_name, im) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
cv2.imwrite(im_name, im) | |
cv2.imwrite(im_name, im) |
@@ -0,0 +1,89 @@ | |||
# This file is licensed under the Apache License v2.0 with LLVM Exceptions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this CMakeList.txt needed? Testing is only supported through a Python test.py file.
clean: | ||
rm -rf build/*.elf* build/*.lst build/*.bif log* build/${mlirFileName}.mlir.prj build/*.xclbin sim \ | ||
build/chess* build/insts.txt \ | ||
build/*.log build/aie_partition.json build/*.bin build/BOOT.BIN _x test.exe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no test.exe being build
quant_model = quantize_model( | ||
model_aie, | ||
backend="flexml", | ||
scale_factor_type="po2_scale", # Ensuring scale factors are powers of two |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
scale_factor_type="po2_scale", # Ensuring scale factors are powers of two | |
scale_factor_type="po2_scale", # Ensuring scale factors are powers of two |
if name.endswith(".bias"): | ||
param.data.fill_(0) | ||
|
||
# Calculate combined scales |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[black] reported by reviewdog 🐶
# Calculate combined scales | |
# Calculate combined scales |
@denolf, added a README and made the requested changes. |
No description provided.