1/* 2 * Copyright 2023 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17syntax = "proto3"; 18 19package fcp.aggregation; 20 21// Data types for individual tensor values. 22enum DataType { 23 // The constants below should be kept in sync with tensorflow::Datatype: 24 // https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/framework/types.proto 25 // While not strictly required, that has a number of benefits, including 26 // easier porting of tensors from tensorflow::Tensor to aggregation tensors. 27 DT_INVALID = 0; 28 DT_FLOAT = 1; 29 DT_DOUBLE = 2; 30 DT_INT32 = 3; 31 DT_STRING = 7; 32 DT_INT64 = 9; 33 // TODO(team): Add other types 34} 35 36// Tensor shape (e.g. dimensions) 37message TensorShapeProto { 38 // Sizes of each dimension in the tensor. 39 // Values must be >= -1, however values of -1 are reserved for "unknown". 40 // 41 // The order of entries in `dim_sizes` matters: It indicates the layout of the 42 // values in the tensor in-memory representation. 43 // 44 // The first entry in `dim_sizes` is the outermost dimension used to layout 45 // the values, the last entry is the innermost dimension. This matches the 46 // in-memory layout of row-major tensors. 47 // 48 // A scalar tensor has a shape with zero dimensions. 49 repeated int64 dim_sizes = 1; 50} 51 52// This message describes aggregation tensor name, type, and shape. 53message TensorSpecProto { 54 // Tensor name 55 string name = 1; 56 57 // Type of the tensor values. 58 DataType dtype = 2; 59 60 // Shape of the tensor. 61 TensorShapeProto shape = 3; 62} 63 64// Optional descriptor of the sparse index encoding, that is applicable only 65// to sparse tensors. If this message is empty (default) that means that 66// the tensor is dense. 67// The best way to think about SparsityEncoding as a way to describe mapping 68// of the indices in the tensor content to the indices in the dense tensor. 69message SparsityEncoding { 70 // TODO(team): Implement SparsityEncoding. 71} 72 73// Protocol buffer representation of a tensor. 74message TensorProto { 75 // Type of the tensor values. 76 DataType dtype = 1; 77 78 // Shape of the tensor. 79 TensorShapeProto shape = 2; 80 81 // Optional descriptor of sparse index encoding. 82 SparsityEncoding sparsity_encoding = 3; 83 84 // Serialized tensor values packed into a single blob. 85 // The exact format of the blob depends on dtype. 86 // 87 // For numeric data types, the following applies: 88 // For a dense tensor, the content matches in-memory representation of a 89 // C-style row-major multi-dimensional array of values. 90 // For a sparse tensor, the content matches in-memory representation of a 91 // one dimensional array of non-zero values, which order is described by 92 // the `sparsity_encoding`. 93 // The values must be encoded using little-endian byte layout. 94 bytes content = 4; 95} 96