Skip to content

add sparse quantization (no simd optimization)#517

Merged
inabao merged 13 commits intomainfrom
support_sparse_in_hgraph
Apr 19, 2025
Merged

add sparse quantization (no simd optimization)#517
inabao merged 13 commits intomainfrom
support_sparse_in_hgraph

Conversation

@inabao
Copy link
Collaborator

@inabao inabao commented Mar 20, 2025

related to:#324

@inabao inabao added kind/feature New feature or request version/0.15 labels Mar 20, 2025
@inabao inabao self-assigned this Mar 20, 2025
@inabao inabao force-pushed the support_sparse_in_hgraph branch from 0e68ad7 to 539c8c2 Compare March 21, 2025 07:01
@codecov
Copy link

codecov bot commented Mar 21, 2025

Codecov Report

Attention: Patch coverage is 86.42534% with 30 lines in your changes missing coverage. Please review.

@@            Coverage Diff             @@
##             main     #517      +/-   ##
==========================================
- Coverage   90.94%   90.70%   -0.25%     
==========================================
  Files         189      194       +5     
  Lines       11562    11812     +250     
==========================================
+ Hits        10515    10714     +199     
- Misses       1047     1098      +51     
Flag Coverage Δ
cpp 90.70% <86.42%> (-0.25%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
common 93.26% <ø> (-1.40%) ⬇️
datacell 92.14% <86.42%> (-0.54%) ⬇️
index 89.41% <ø> (-0.02%) ⬇️
simd 87.24% <ø> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 360af1e...8dc3b35. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@inabao inabao force-pushed the support_sparse_in_hgraph branch 3 times, most recently from 478961e to e3503b8 Compare March 31, 2025 14:29
@inabao inabao force-pushed the support_sparse_in_hgraph branch 2 times, most recently from 3b5d927 to 10f7fac Compare April 9, 2025 08:37
Copy link
Collaborator

@jiaweizone jiaweizone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PART-I

uint32_t current_offset_{0};
};

template <typename QuantTmpl, typename IOTmpl>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move all implements to .inl file and in file end #include this .inl file

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

void
SparseVectorDataCell<QuantTmpl, IOTmpl>::BatchInsertVector(const void* vectors,
InnerIdType count,
InnerIdType* idx) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idx -> idx_vec ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if (idx == nullptr) {
idx = idx_ptr.data();
for (InnerIdType i = 0; i < count; ++i) {
idx[i] = total_count_ + i;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test case

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

void
SparseVectorDataCell<QuantTmpl, IOTmpl>::InsertVector(const void* vector, InnerIdType idx) {
if (idx == std::numeric_limits<InnerIdType>::max()) {
idx = total_count_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why change the sparse vector idx ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed this part

idx = total_count_;
++total_count_;
} else {
total_count_ = std::max(total_count_, idx + 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: total_count_ in here is means 'max_idx’ ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the input ID exceeds the current total_count, update the total_count.

template <typename QuantTmpl, typename IOTmpl>
MetricType
SparseVectorDataCell<QuantTmpl, IOTmpl>::GetMetricType() {
return this->quantizer_->Metric();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add test

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/parameter.h Outdated
CHECK_ARGUMENT(json.contains("type"), "params must have type"); // TODO(LHT): "type" rename
return json["type"];
CHECK_ARGUMENT(json.contains(QUANTIZATION_TYPE_KEY),
"params must have type"); // TODO(LHT): "type" rename
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here let TryToParseType to get QUANTIZATION_TYPE_KEY type ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

inabao added 10 commits April 17, 2025 14:43
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
@inabao inabao force-pushed the support_sparse_in_hgraph branch from 718cbf5 to 01bea36 Compare April 17, 2025 06:49
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
#include "io/io_headers.h"
#include "quantization/quantizer_headers.h"
#include "quantization/sparse_quantization/sparse_quantizer.h"
#include "sparse_vector_datacell.inl"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move #include "sparse_vector_datacell.inl to sparse_vector_datacell.h file bottom

Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Signed-off-by: jinjiabao.jjb <jinjiabao.jjb@antgroup.com>
Copy link
Collaborator

@LHT129 LHT129 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@wxyucs wxyucs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@inabao inabao merged commit 1edaaf1 into main Apr 19, 2025
22 of 23 checks passed
@inabao inabao deleted the support_sparse_in_hgraph branch April 19, 2025 04:48

void
BatchInsertVector(const float* vectors, InnerIdType count, InnerIdType* idx) override;
BatchInsertVector(const void* vectors, InnerIdType count, InnerIdType* idx) override;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idx -> idx_vec

template <typename QuantTmpl, typename IOTmpl>
void
FlattenDataCell<QuantTmpl, IOTmpl>::BatchInsertVector(const float* vectors,
FlattenDataCell<QuantTmpl, IOTmpl>::BatchInsertVector(const void* vectors,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idx -> idx_vec

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


virtual void
BatchInsertVector(const float* vectors, InnerIdType count, InnerIdType* idx = nullptr) = 0;
BatchInsertVector(const void* vectors, InnerIdType count, InnerIdType* idx = nullptr) = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idx -> idx_vec

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
auto* codes = reinterpret_cast<uint8_t*>(allocator_->Allocate(code_size));
quantizer_->EncodeOne((const float*)vector, codes);
uint32_t now_current_offset = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now_current_offset -> new_offset ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


void
FromJson(const JsonType& json) override {
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no implement ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, there is no parameter for sparse quantizer now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants