-
Couldn't load subscription status.
- Fork 704
Introduce data schema to store raw tensors #6540
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f24016d
Introduce data schema to store raw tensors
lucylq 229527e
Update on "Introduce data schema to store raw tensors"
lucylq cec36f6
Update on "Introduce data schema to store raw tensors"
lucylq 859cf52
Update on "Introduce data schema to store raw tensors"
lucylq c8d6489
Update on "Introduce data schema to store raw tensors"
lucylq d7b7162
Update on "Introduce data schema to store raw tensors"
lucylq 9043914
Update on "Introduce data schema to store raw tensors"
lucylq c829c57
Update on "Introduce data schema to store raw tensors"
lucylq 70c9f7f
Update on "Introduce data schema to store raw tensors"
lucylq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| # All rights reserved. | ||
| # | ||
| # This source code is licensed under the BSD-style license found in the | ||
| # LICENSE file in the root directory of this source tree. | ||
|
|
||
|
|
||
| from dataclasses import dataclass | ||
| from typing import List | ||
|
|
||
| from executorch.exir.scalar_type import ScalarType | ||
|
|
||
| # Note: check executorch/schema/data.fbs for explanations of these fields. | ||
|
|
||
|
|
||
| @dataclass | ||
| class TensorMetadata: | ||
| fully_qualified_name: str | ||
| scalar_type: ScalarType | ||
| dim_sizes: List[int] | ||
| dim_order: List[bytes] | ||
|
|
||
| segment_index: int | ||
| offset: int | ||
|
|
||
|
|
||
| @dataclass | ||
| class DataSegment: | ||
| offset: int | ||
| size: int | ||
|
|
||
|
|
||
| @dataclass | ||
| class Data: | ||
| version: int | ||
| tensor_alignment: int | ||
| tensor_segments: List[TensorMetadata] | ||
| data_segments: List[DataSegment] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| include "scalar_type.fbs"; | ||
| namespace executorch_flatbuffer; | ||
|
|
||
| // Update after BC breaking changes. | ||
| file_identifier "DT01"; | ||
| file_extension "ptd"; | ||
|
|
||
| table TensorMetadata { | ||
| // The unique id used to connect the data and program. | ||
| fully_qualified_name: string; | ||
| scalar_type: ScalarType; | ||
|
|
||
| // Size of each dimension. | ||
| dim_sizes: [int32]; | ||
|
|
||
| // Specifies in what order the dimensions are laid out in memory (from outer | ||
| // to inner). | ||
| // | ||
| // For example, given a rank 3 Tensor of size (3, 5, 2). If we name | ||
| // dimensions: [row, column, batch], then a dim_order of: | ||
| // - (2, 0, 1) represents a [batch, row, column] ordering where "column" is | ||
| // the innermost dimension, then comes "row", and the outermost dimension is | ||
| // "batch". | ||
| // - (0, 2, 1) represents a [row, batch, column] ordering where "column" is | ||
| // the innermost dimension, then comes "batch", and the outermost dimension | ||
| // is "row". | ||
| dim_order: [uint8]; | ||
|
|
||
| // Segment index that the tensor data is stored in. | ||
| segment_index: uint32; | ||
|
|
||
| // Tensor offsets are relative to each TensorSegment. | ||
| // To retrieve a given tensor: | ||
| // 1. segment_base_offset: from the file header. | ||
| // 2. segment offset: segments[segment_index].offset | ||
| // This is likely to be 0 (all the tensors in one segment). | ||
| // 3. tensor offset: tensor_segments[i].tensor_metadata[j].offset | ||
| // Find the relevant index j by matching on tensor fqn. | ||
| offset: uint64; | ||
| } | ||
|
|
||
| table DataSegment { | ||
| // Segment offsets are relative to the segment base offset provided in | ||
| // the extended file header. Segments will typically be aligned in a | ||
| // way to make it possible to use mmap() to load them. | ||
| offset: uint64; | ||
|
|
||
| // The size in bytes of valid data starting at the offset. The segment | ||
| // data may be followed by padding before the segment that follows it, | ||
| // to make it easier to use mmap(). | ||
| size: uint64; | ||
| } | ||
|
|
||
| table DataFile { | ||
| // Schema version. | ||
| version: uint32; | ||
|
|
||
| // Alignment for each tensor in bytes. Offsets of the tensor provided | ||
| // in TensorMetadata.offset are aligned to tensor_alignment. | ||
| tensor_alignment: uint32; | ||
|
|
||
| // Tensor information. | ||
| tensor_segments: [TensorMetadata]; | ||
|
|
||
| // Data segments. | ||
| segments: [DataSegment]; | ||
| } | ||
|
|
||
| root_type DataFile; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: just sizes not dim_sizes