UserWarning: Mutation on a buffer in the model is detected. ExecuTorch assumes buffers that are mutated in the graph have a meaningless initial state

I have exported model to Executorch program, and the file is saved correctly in directory. But I enountered warning like this

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># To see more debug info, please use `graph_module.print_readable()`
Model successfully exported to model.pte
/usr/local/lib/python3.10/dist-packages/executorch/exir/emit/_emitter.py:1512: UserWarning: Mutation on a buffer in the model is detected. ExecuTorch assumes buffers that are mutated in the graph have a meaningless initial state, only the shape and dtype will be serialized.
warnings.warn(
</code>
<code># To see more debug info, please use `graph_module.print_readable()` Model successfully exported to model.pte /usr/local/lib/python3.10/dist-packages/executorch/exir/emit/_emitter.py:1512: UserWarning: Mutation on a buffer in the model is detected. ExecuTorch assumes buffers that are mutated in the graph have a meaningless initial state, only the shape and dtype will be serialized. warnings.warn( </code>
# To see more debug info, please use `graph_module.print_readable()`
Model successfully exported to model.pte
/usr/local/lib/python3.10/dist-packages/executorch/exir/emit/_emitter.py:1512: UserWarning: Mutation on a buffer in the model is detected. ExecuTorch assumes buffers that are mutated in the graph have a meaningless initial state, only the shape and dtype will be serialized.
  warnings.warn(

Yes, the warning was not completed, so I was confused about whether this warning would have a big impact on the program I was going to run or not.

I use T4 in google colab to execute this function.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>
def quantize_model(model: nn.Module, example_inputs: tuple) -> nn.Module:
print(f"Original model architecture:n{model}")
# Initialize quantizer with symmetric quantization configuration
quantizer = XNNPACKQuantizer()
operator_config = get_symmetric_quantization_config(is_per_channel=False)
quantizer.set_global(operator_config)
# Prepare model for quantization
pre_autograd_model = export_for_training(model, example_inputs).module()
prepared_model = prepare_pt2e(pre_autograd_model, quantizer)
# Calibrate and convert the model
prepared_model(*example_inputs)
quantized_model = convert_pt2e(prepared_model)
print(f"Quantized model architecture:n{quantized_model}")
return quantized_model
def export_to_executorch(model: nn.Module, example_inputs: tuple, output_path: str):
edge_program = to_edge_transform_and_lower(
export(model, example_inputs),
compile_config=EdgeCompileConfig(_check_ir_validity=True),
partitioner=[XnnpackPartitioner()]
)
# Convert to executorch program
executorch_program: exir.ExecutorchProgramManager = edge_program.to_executorch(
ExecutorchBackendConfig(passes=[])
)
# Save the program to file
with open(output_path, "wb") as file:
file.write(executorch_program.buffer)
print(f"Model successfully exported to {output_path}")
def main():
# Define example inputs
example_inputs = (torch.randn(1, 1, 256, 256),)
# Create and quantize model
model = ResEmoteNet() # Assuming this class is defined elsewhere
quantized_model = quantize_model(model, example_inputs)
# Export the quantized model
export_to_executorch(
model=quantized_model,
example_inputs=example_inputs,
output_path="model.pte"
)
if __name__ == "__main__":
main()
</code>
<code> def quantize_model(model: nn.Module, example_inputs: tuple) -> nn.Module: print(f"Original model architecture:n{model}") # Initialize quantizer with symmetric quantization configuration quantizer = XNNPACKQuantizer() operator_config = get_symmetric_quantization_config(is_per_channel=False) quantizer.set_global(operator_config) # Prepare model for quantization pre_autograd_model = export_for_training(model, example_inputs).module() prepared_model = prepare_pt2e(pre_autograd_model, quantizer) # Calibrate and convert the model prepared_model(*example_inputs) quantized_model = convert_pt2e(prepared_model) print(f"Quantized model architecture:n{quantized_model}") return quantized_model def export_to_executorch(model: nn.Module, example_inputs: tuple, output_path: str): edge_program = to_edge_transform_and_lower( export(model, example_inputs), compile_config=EdgeCompileConfig(_check_ir_validity=True), partitioner=[XnnpackPartitioner()] ) # Convert to executorch program executorch_program: exir.ExecutorchProgramManager = edge_program.to_executorch( ExecutorchBackendConfig(passes=[]) ) # Save the program to file with open(output_path, "wb") as file: file.write(executorch_program.buffer) print(f"Model successfully exported to {output_path}") def main(): # Define example inputs example_inputs = (torch.randn(1, 1, 256, 256),) # Create and quantize model model = ResEmoteNet() # Assuming this class is defined elsewhere quantized_model = quantize_model(model, example_inputs) # Export the quantized model export_to_executorch( model=quantized_model, example_inputs=example_inputs, output_path="model.pte" ) if __name__ == "__main__": main() </code>

def quantize_model(model: nn.Module, example_inputs: tuple) -> nn.Module:
 
    print(f"Original model architecture:n{model}")
    
    # Initialize quantizer with symmetric quantization configuration
    quantizer = XNNPACKQuantizer()
    operator_config = get_symmetric_quantization_config(is_per_channel=False)
    quantizer.set_global(operator_config)
    
    # Prepare model for quantization
    pre_autograd_model = export_for_training(model, example_inputs).module()
    prepared_model = prepare_pt2e(pre_autograd_model, quantizer)
    
    # Calibrate and convert the model
    prepared_model(*example_inputs)
    quantized_model = convert_pt2e(prepared_model)
    
    print(f"Quantized model architecture:n{quantized_model}")
    return quantized_model

def export_to_executorch(model: nn.Module, example_inputs: tuple, output_path: str):

    edge_program = to_edge_transform_and_lower(
        export(model, example_inputs),
        compile_config=EdgeCompileConfig(_check_ir_validity=True),
        partitioner=[XnnpackPartitioner()]
    )
    
    # Convert to executorch program
    executorch_program: exir.ExecutorchProgramManager = edge_program.to_executorch(
        ExecutorchBackendConfig(passes=[])
    )
    
    # Save the program to file
    with open(output_path, "wb") as file:
        file.write(executorch_program.buffer)
        print(f"Model successfully exported to {output_path}")

def main():
    # Define example inputs
    example_inputs = (torch.randn(1, 1, 256, 256),)
    
    # Create and quantize model
    model = ResEmoteNet()  # Assuming this class is defined elsewhere
    quantized_model = quantize_model(model, example_inputs)
    
    # Export the quantized model
    export_to_executorch(
        model=quantized_model,
        example_inputs=example_inputs,
        output_path="model.pte"
    )

if __name__ == "__main__":
    main()

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật