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

Generate model with int4 weight ( maybe single op model ) #12751

Open
Tracked by #12741
chunseoklee opened this issue Mar 14, 2024 · 2 comments
Open
Tracked by #12741

Generate model with int4 weight ( maybe single op model ) #12751

chunseoklee opened this issue Mar 14, 2024 · 2 comments

Comments

@chunseoklee
Copy link
Contributor

chunseoklee commented Mar 14, 2024

There are several options to generate this :

@chunseoklee
Copy link
Contributor Author

This is one op circle model( FullyConnected_INT4.zip ) generated by flatcing with json file below :

op: FC
I : f32 (1,2)
W: int4 (4,2) packed
A: f32 (1,4)

{
  operator_codes: [
    {                                                                                                                                                                                                                                                                                                                                                                                                                                      deprecated_builtin_code: 9,
      builtin_code: "FULLY_CONNECTED"
    }
  ],
  subgraphs: [
    {
      tensors: [
        {
          shape: [
            1,
            2
          ],
          buffer: 1,
          name: "in"
        },
        {
          shape: [
            4,
            2
          ],
          type: "INT4",
          buffer: 2,
          name: "weight",
          quantization: {
            min: [
              0.0
            ],
            max: [
              1.0
            ],
            scale: [
              0.000554
            ],
            zero_point: [
              0
            ]
          }
        },
        {
          shape: [
            4
          ],
          buffer: 3,
          name: "bias"
        },
        {
          shape: [
            1,
            4
          ],
          buffer: 4,
          name: "out"
        }
      ],
      inputs: [
        0,
      ],
      outputs: [
        3
      ],
      operators: [
        {
          inputs: [
            0,
            1,
            2
          ],
          outputs: [
            3
          ],
          builtin_options_type: "FullyConnectedOptions",
          builtin_options: {
          }
        }
      ],
      name: "main"
    }
  ],
  description: "ONE-tflite2circle",
  buffers: [
    {

    },
    {
    },
    { data : [16,0,255,0]
    },
    { data : [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]
    },
    {
    },
  ]
}

@chunseoklee
Copy link
Contributor Author

nnfw_api_test model : 367b9bb

TEST_F(GenModelTest, OneOp_FullyConnected_Int4Weight)
{
CircleGen cgen;
// clang-format off
// This is packed weight for [0, 1, 0, 0, -1, -1 ,0, 0]
std::vector<uint8_t> weight_data{ 16, 0, 255, 0 };
std::vector<float> bias_data{ 0, 1, 2, 3 };
// clang-format on
uint32_t weight_buf = cgen.addBuffer(weight_data);
uint32_t bias_buf = cgen.addBuffer(bias_data);
int input = cgen.addTensor({{1, 2}, circle::TensorType::TensorType_FLOAT32});
std::vector<float> weight_scales = {0.5};
std::vector<int64_t> weight_zeropoints = {0};
int weight = cgen.addTensor({{4, 2}, circle::TensorType::TensorType_INT4, weight_buf}, weight_scales, weight_zeropoints);
int bias = cgen.addTensor({{4}, circle::TensorType::TensorType_FLOAT32, bias_buf});
int output = cgen.addTensor({{1, 4}, circle::TensorType::TensorType_FLOAT32});
cgen.addOperatorFullyConnected({{input, weight, bias}, {output}});
cgen.setInputsAndOutputs({input}, {output});
_context = std::make_unique<GenModelTestContext>(cgen.finish());
_context->addTestCase(
uniformTCD<float>({{1, 3}}, {{1.5 , 1, 0, 3}}));
_context->setBackends({"cpu"});
SUCCEED();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant