Skip to content

Commit

Permalink
[TFLite] Added implementation details (openvinotoolkit#24835)
Browse files Browse the repository at this point in the history
### Details:
 - Added an implementation details for sparse-tensors reading

### Tickets:
 - N/A

---------

Co-authored-by: Roman Kazantsev <[email protected]>
  • Loading branch information
gkrivor and rkazants authored Jun 4, 2024
1 parent 52d0a44 commit c45a46e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/frontends/tensorflow_lite/src/sparsity_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@ bool ov::frontend::tensorflow_lite::SparsityInfo::is_copyable() const {
}

// Unpacks sparse data. Supports only case when sparse tensor has only one sparse dimension [DENSE, ..., DENSE, SPARSE]
// TensorFlow Lite uses a specific format for storing sparse data (TACO):
// It uses three 1D arrays/1D tensors/vectors:
// values - stored in model's buffers
// segments/positions - list of row's start positions
// indices - list of value indexes in a row (size is equal to values)
// Algorithm is next, and it should be easily modified later for 2D sparse matrices (that's why it uses a 2D approach):
// 1. Get a first segment position, set idx = 0
// In a cycle
// 2. Get next segment position
// 3. Get an element_count by a difference between current segment position and last_segment position.
// If diff between last and current segment is 0 it means an empty row (contains only default values).
// In cycle for each element in a segment:
// 4. Calculate a row_offset using idx-th index by indices and element_size (fp16/fp32/etc...)
// 5. Put an idx-th value to a found target dest + row_offset
// 6. Move to a next row
template <typename T, typename U>
static void read_sparse_data(uint8_t* dest,
uint8_t* dest_end,
Expand Down

0 comments on commit c45a46e

Please sign in to comment.