Skip to content
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

Why can't we set the precision of all layers to fp16 or fp32? #3177

Closed
sanbuphy opened this issue Aug 1, 2023 · 10 comments
Closed

Why can't we set the precision of all layers to fp16 or fp32? #3177

sanbuphy opened this issue Aug 1, 2023 · 10 comments
Assignees
Labels
triaged Issue has been triaged by maintainers

Comments

@sanbuphy
Copy link

sanbuphy commented Aug 1, 2023

Description

Hello, I'm trying to set the precision of specific layers to fp32, but after setting some layers, I don't see any improvement (the final output is still NaN). To troubleshoot this issue, I wanted to verify if setting it to fp32 actually makes a difference. However, I encountered an error when attempting to do so. Could you please explain the reason behind this error? Thank you very much.

Here is my code:

config.set_flag(trt.BuilderFlag.FP16)
config.set_flag(trt.BuilderFlag.OBEY_PRECISION_CONSTRAINTS)

for layer in network:
    layer.precision =  trt.float32

image

image

@zerollzeng
Copy link
Collaborator

As the warning say: some layers is force to running in INT32, you can not set those layers to FP32.

@zerollzeng zerollzeng self-assigned this Aug 3, 2023
@zerollzeng zerollzeng added the triaged Issue has been triaged by maintainers label Aug 3, 2023
@sanbuphy
Copy link
Author

sanbuphy commented Aug 3, 2023

As the warning say: some layers is force to running in INT32, you can not set those layers to FP32.

How can i skip that layer?

@nvluxiaoz
Copy link
Contributor

nvluxiaoz commented Aug 3, 2023

I think you might do

if layer.precision == trt.float16:
    layer.precision == trt.float32

@ninono12345
Copy link

Hello @nvluxiaoz , can you please explain, how to force precision to trt.float32 and run this from trtexec command line? If not can you provide a code snippet? Thank You

@zerollzeng
Copy link
Collaborator

To avoid the warning, just don't set those layers precision to FP32, or just safely ignore it.

@sanbuphy
Copy link
Author

To avoid the warning, just don't set those layers precision to FP32, or just safely ignore it.

I want to skip that layers, but i don't know how to identify the layers

@zerollzeng
Copy link
Collaborator

Filter with layer name or layer type?

@ttyio
Copy link
Collaborator

ttyio commented Apr 16, 2024

closing since no activity for more than 3 weeks, thanks all!

@ttyio ttyio closed this as completed Apr 16, 2024
@focusunsink
Copy link

why closing, this is important.

@focusunsink
Copy link

for i in range(network.num_layers):

        #     layer = network.get_layer(i)
        #     if 'norm' in layer.name:
        #         print("this is a layernorm", layer.type, layer.name, layer.precision)
        #         #layer.precision = trt.DataType.FLOAT
        #     elif layer.type == trt.LayerType.MATRIX_MULTIPLY:
        #         print("this is a matmul", layer.type, layer.name, layer.precision)
        #         #layer.precision = trt.float16
        #     else:
        #         pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged Issue has been triaged by maintainers
Projects
None yet
Development

No branches or pull requests

6 participants