tensorflow

package
v2.14.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 8, 2023 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	QuantizationPrecision_name = map[int32]string{
		0: "PRECISION_UNSPECIFIED",
		1: "PRECISION_FULL",
		2: "PRECISION_W4A4",
		3: "PRECISION_W4A8",
		4: "PRECISION_W8A8",
	}
	QuantizationPrecision_value = map[string]int32{
		"PRECISION_UNSPECIFIED": 0,
		"PRECISION_FULL":        1,
		"PRECISION_W4A4":        2,
		"PRECISION_W4A8":        3,
		"PRECISION_W8A8":        4,
	}
)

Enum value maps for QuantizationPrecision.

View Source
var (
	OpSet_name = map[int32]string{
		0: "OP_SET_UNSPECIFIED",
		1: "TF",
		2: "XLA",
		3: "UNIFORM_QUANTIZED",
	}
	OpSet_value = map[string]int32{
		"OP_SET_UNSPECIFIED": 0,
		"TF":                 1,
		"XLA":                2,
		"UNIFORM_QUANTIZED":  3,
	}
)

Enum value maps for OpSet.

View Source
var (
	QuantizationMethod_Method_name = map[int32]string{
		0: "METHOD_UNSPECIFIED",
	}
	QuantizationMethod_Method_value = map[string]int32{
		"METHOD_UNSPECIFIED": 0,
	}
)

Enum value maps for QuantizationMethod_Method.

View Source
var (
	QuantizationMethod_ExperimentalMethod_name = map[int32]string{
		0: "EXPERIMENTAL_METHOD_UNSPECIFIED",
		1: "STATIC_RANGE",
		2: "DYNAMIC_RANGE",
		3: "WEIGHT_ONLY",
	}
	QuantizationMethod_ExperimentalMethod_value = map[string]int32{
		"EXPERIMENTAL_METHOD_UNSPECIFIED": 0,
		"STATIC_RANGE":                    1,
		"DYNAMIC_RANGE":                   2,
		"WEIGHT_ONLY":                     3,
	}
)

Enum value maps for QuantizationMethod_ExperimentalMethod.

View Source
var (
	UnitWiseQuantizationPrecision_UnitType_name = map[int32]string{
		0: "UNIT_UNSPECIFIED",
		1: "UNIT_NODE",
		2: "UNIT_OP",
	}
	UnitWiseQuantizationPrecision_UnitType_value = map[string]int32{
		"UNIT_UNSPECIFIED": 0,
		"UNIT_NODE":        1,
		"UNIT_OP":          2,
	}
)

Enum value maps for UnitWiseQuantizationPrecision_UnitType.

View Source
var File_tensorflow_compiler_mlir_quantization_tensorflow_exported_model_proto protoreflect.FileDescriptor
View Source
var File_tensorflow_compiler_mlir_quantization_tensorflow_quantization_options_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type ExportedModel added in v2.12.0

type ExportedModel struct {
	GraphDef *framework.GraphDef `protobuf:"bytes,1,opt,name=graph_def,json=graphDef,proto3" json:"graph_def,omitempty"`
	// Name of the initialization node (TF Operation) used for initializing
	// resources like hash tables upon loading.
	InitNodeName string `protobuf:"bytes,2,opt,name=init_node_name,json=initNodeName,proto3" json:"init_node_name,omitempty"`
	// Path to the directory where checkpoint files are saved. This directoy is
	// not expected to be persistent (usually a temporary directory). When
	// fetching the restore op (see `restore_node_name`), this value is provided
	// to the "file_prefix" tensor to identify the checkpoint directory.
	CheckpointDir string `protobuf:"bytes,5,opt,name=checkpoint_dir,json=checkpointDir,proto3" json:"checkpoint_dir,omitempty"`
	// Function name -> function alias mapping. This associates the quantized
	// functions to the original functions' aliases. This information will be used
	// to populate `MetaInfoDef`s `function_aliases` when the quantized model is
	// exported to the saved model. This field is usually only populated for the
	// TF2 models.
	FunctionAliases map[string]string `` /* 194-byte string literal not displayed */
	// Holds information about the asset files used for the model. It essentially
	// associates asset file names with the tensors to which the asset file names
	// should be fed.
	AssetFileDefs []*protobuf.AssetFileDef `protobuf:"bytes,8,rep,name=asset_file_defs,json=assetFileDefs,proto3" json:"asset_file_defs,omitempty"`
	// SaverDef including the information required for saving and restoring
	// variables. This field is not set if there are no variables in the exported
	// graph. If set, the fields `version`, `filename_tensor_name`,
	// `restore_op_name` and `save_tensor_name` are populated.
	SaverDef *protobuf.SaverDef `protobuf:"bytes,10,opt,name=saver_def,json=saverDef,proto3" json:"saver_def,omitempty"`
	// contains filtered or unexported fields
}

Represents an exported TensorFlow model. It consists of a GraphDef and extra metadata required for building a SavedModel. This message is primarily used to "export" the model produced from various quantization passes in c++ to Python layer. Next ID: 11

func (*ExportedModel) Descriptor deprecated added in v2.12.0

func (*ExportedModel) Descriptor() ([]byte, []int)

Deprecated: Use ExportedModel.ProtoReflect.Descriptor instead.

func (*ExportedModel) GetAssetFileDefs added in v2.13.0

func (x *ExportedModel) GetAssetFileDefs() []*protobuf.AssetFileDef

func (*ExportedModel) GetCheckpointDir added in v2.12.0

func (x *ExportedModel) GetCheckpointDir() string

func (*ExportedModel) GetFunctionAliases added in v2.12.0

func (x *ExportedModel) GetFunctionAliases() map[string]string

func (*ExportedModel) GetGraphDef added in v2.12.0

func (x *ExportedModel) GetGraphDef() *framework.GraphDef

func (*ExportedModel) GetInitNodeName added in v2.12.0

func (x *ExportedModel) GetInitNodeName() string

func (*ExportedModel) GetSaverDef added in v2.13.0

func (x *ExportedModel) GetSaverDef() *protobuf.SaverDef

func (*ExportedModel) ProtoMessage added in v2.12.0

func (*ExportedModel) ProtoMessage()

func (*ExportedModel) ProtoReflect added in v2.12.0

func (x *ExportedModel) ProtoReflect() protoreflect.Message

func (*ExportedModel) Reset added in v2.12.0

func (x *ExportedModel) Reset()

func (*ExportedModel) String added in v2.12.0

func (x *ExportedModel) String() string

type FreezeAllVariables added in v2.12.0

type FreezeAllVariables struct {

	// Setting this to true freezes all variables to constants during
	// quantization. Setting this to `false` is an experimental feature and does
	// not have stability guarantees.
	Enabled bool `protobuf:"varint,1,opt,name=enabled,proto3" json:"enabled,omitempty"`
	// contains filtered or unexported fields
}

Configurations for variable freezing during quantization passes. NEXT ID: 2

func (*FreezeAllVariables) Descriptor deprecated added in v2.12.0

func (*FreezeAllVariables) Descriptor() ([]byte, []int)

Deprecated: Use FreezeAllVariables.ProtoReflect.Descriptor instead.

func (*FreezeAllVariables) GetEnabled added in v2.12.0

func (x *FreezeAllVariables) GetEnabled() bool

func (*FreezeAllVariables) ProtoMessage added in v2.12.0

func (*FreezeAllVariables) ProtoMessage()

func (*FreezeAllVariables) ProtoReflect added in v2.12.0

func (x *FreezeAllVariables) ProtoReflect() protoreflect.Message

func (*FreezeAllVariables) Reset added in v2.12.0

func (x *FreezeAllVariables) Reset()

func (*FreezeAllVariables) String added in v2.12.0

func (x *FreezeAllVariables) String() string

type OpSet

type OpSet int32

List of supported opsets to deploy the quantized model. The quantized model contains different set of ops depending on the opset. NEXT ID: 4

const (
	OpSet_OP_SET_UNSPECIFIED OpSet = 0 // go/do-include-enum-unspecified
	// Uses TF ops that mimic quantization behavior. Used when the corresponding
	// integer op is not yet present.
	OpSet_TF OpSet = 1
	// Uses TF XLA ops
	OpSet_XLA OpSet = 2
	// Uses TF Uniform Quantized ops
	OpSet_UNIFORM_QUANTIZED OpSet = 3
)

func (OpSet) Descriptor

func (OpSet) Descriptor() protoreflect.EnumDescriptor

func (OpSet) Enum

func (x OpSet) Enum() *OpSet

func (OpSet) EnumDescriptor deprecated

func (OpSet) EnumDescriptor() ([]byte, []int)

Deprecated: Use OpSet.Descriptor instead.

func (OpSet) Number

func (x OpSet) Number() protoreflect.EnumNumber

func (OpSet) String

func (x OpSet) String() string

func (OpSet) Type

func (OpSet) Type() protoreflect.EnumType

type QuantizationMethod

type QuantizationMethod struct {

	// Quantization method is either exprimental or non-experimental method.
	//
	// Types that are assignable to MethodOneof:
	//
	//	*QuantizationMethod_Method_
	//	*QuantizationMethod_ExperimentalMethod_
	MethodOneof isQuantizationMethod_MethodOneof `protobuf_oneof:"method_oneof"`
	// contains filtered or unexported fields
}

Model quantization method for optimization.

Various techniques for model quantization are defined within this message along with a field that specifies a method to be used for a particular quantization request. NEXT ID: 3

func (*QuantizationMethod) Descriptor deprecated

func (*QuantizationMethod) Descriptor() ([]byte, []int)

Deprecated: Use QuantizationMethod.ProtoReflect.Descriptor instead.

func (*QuantizationMethod) GetExperimentalMethod

func (x *QuantizationMethod) GetExperimentalMethod() QuantizationMethod_ExperimentalMethod

func (*QuantizationMethod) GetMethod

func (*QuantizationMethod) GetMethodOneof

func (m *QuantizationMethod) GetMethodOneof() isQuantizationMethod_MethodOneof

func (*QuantizationMethod) ProtoMessage

func (*QuantizationMethod) ProtoMessage()

func (*QuantizationMethod) ProtoReflect

func (x *QuantizationMethod) ProtoReflect() protoreflect.Message

func (*QuantizationMethod) Reset

func (x *QuantizationMethod) Reset()

func (*QuantizationMethod) String

func (x *QuantizationMethod) String() string

type QuantizationMethod_ExperimentalMethod

type QuantizationMethod_ExperimentalMethod int32

Experimental quantization methods. These methods are either not implemented or provided with an unstable behavior.

const (
	// This should never be used. Using this will generally result in an error.
	QuantizationMethod_EXPERIMENTAL_METHOD_UNSPECIFIED QuantizationMethod_ExperimentalMethod = 0 // go/do-include-enum-unspecified
	// Static range quantization. Quantized tensor values' ranges are statically
	// determined.
	QuantizationMethod_STATIC_RANGE QuantizationMethod_ExperimentalMethod = 1
	// Dynamic range quantization. Quantized tensor values' ranges are
	// determined in the graph executions. The weights are quantized during
	// conversion.
	QuantizationMethod_DYNAMIC_RANGE QuantizationMethod_ExperimentalMethod = 2
	// Weight-only quantization. Only weights are quantized during conversion.
	QuantizationMethod_WEIGHT_ONLY QuantizationMethod_ExperimentalMethod = 3
)

func (QuantizationMethod_ExperimentalMethod) Descriptor

func (QuantizationMethod_ExperimentalMethod) Enum

func (QuantizationMethod_ExperimentalMethod) EnumDescriptor deprecated

func (QuantizationMethod_ExperimentalMethod) EnumDescriptor() ([]byte, []int)

Deprecated: Use QuantizationMethod_ExperimentalMethod.Descriptor instead.

func (QuantizationMethod_ExperimentalMethod) Number

func (QuantizationMethod_ExperimentalMethod) String

func (QuantizationMethod_ExperimentalMethod) Type

type QuantizationMethod_ExperimentalMethod_

type QuantizationMethod_ExperimentalMethod_ struct {
	ExperimentalMethod QuantizationMethod_ExperimentalMethod `` /* 152-byte string literal not displayed */
}

type QuantizationMethod_Method

type QuantizationMethod_Method int32

Quantization methods that are supported as a stable API.

const (
	// This should never be used. Using this will generally result in an error.
	QuantizationMethod_METHOD_UNSPECIFIED QuantizationMethod_Method = 0 // go/do-include-enum-unspecified
)

func (QuantizationMethod_Method) Descriptor

func (QuantizationMethod_Method) Enum

func (QuantizationMethod_Method) EnumDescriptor deprecated

func (QuantizationMethod_Method) EnumDescriptor() ([]byte, []int)

Deprecated: Use QuantizationMethod_Method.Descriptor instead.

func (QuantizationMethod_Method) Number

func (QuantizationMethod_Method) String

func (x QuantizationMethod_Method) String() string

func (QuantizationMethod_Method) Type

type QuantizationMethod_Method_

type QuantizationMethod_Method_ struct {
	Method QuantizationMethod_Method `protobuf:"varint,1,opt,name=method,proto3,enum=tensorflow.quantization.QuantizationMethod_Method,oneof"`
}

type QuantizationOptions

type QuantizationOptions struct {

	// The default quantization configuration for the model. If the below
	// unit-wise configuration does not exist, we use this default quantization
	// configuration for the entire model. If the below unit-wise configuration
	// exists, this default one will become the quantization configuration for
	// units that are not specified in unit-wise configurations.
	QuantizationMethod    *QuantizationMethod   `protobuf:"bytes,1,opt,name=quantization_method,json=quantizationMethod,proto3" json:"quantization_method,omitempty"`
	OpSet                 OpSet                 `protobuf:"varint,2,opt,name=op_set,json=opSet,proto3,enum=tensorflow.quantization.OpSet" json:"op_set,omitempty"` // If not specified, it defaults to `XLA`.
	QuantizationPrecision QuantizationPrecision ``                                                                                                                 /* 176-byte string literal not displayed */
	// Quantization precision for each unit. Units can become either
	// nodes or ops, and the mixture of those different units are allowed.
	// If there are conflicts or ambiguity in this unit-wise precision, our
	// quantizer will raise an error.
	UnitWiseQuantizationPrecision []*UnitWiseQuantizationPrecision `` /* 152-byte string literal not displayed */
	// Minimum number of weight elements to apply quantization. Currently only
	// supported for Post-training Dynamic Range Quantization. By default, it is
	// set to 1024. To disable this, set the value to -1 explicitly.
	MinNumElementsForWeights int64 `` /* 140-byte string literal not displayed */
	// When set to `true`, freezes all variables in the model into constants.
	// When set to `false` the model's large constants are converted to variables.
	// Setting this to `false` is an experimental feature and quantization may
	// fail. To quantize models larger than 2 GiB, this should be set to `false`.
	// If not set, it defaults to `true`.
	FreezeAllVariables *FreezeAllVariables `protobuf:"bytes,6,opt,name=freeze_all_variables,json=freezeAllVariables,proto3" json:"freeze_all_variables,omitempty"`
	// Enables chnanel-wise quantizaiton. By default, channel-wise quantization is
	// not applied regardless of the op support. Currently, it is supported for
	// Uniform Quantized opset only.
	EnablePerChannelQuantization bool `` /* 150-byte string literal not displayed */
	// Enables two inputs of an operation to be both tensors.
	// Currently supports MatMul and BatchMatMul ops for XLA.
	// TODO(b/263528090): Check the condition when this feature is beneficial.
	EnableTwoInputTensors bool `` /* 129-byte string literal not displayed */
	// Supports TPU model quantization. If the target model for the quantization
	// is already converted for TPU, this flag may be helpful. Note that this
	// feature may be unstable as it is under the experimental stage.
	ExperimentalEnableTpuModelSupport bool `` /* 167-byte string literal not displayed */
	// Produces legacy weight-only graph where the qconst op(containing quantized
	// values) is followed by a dequantization op.
	EnableLegacyWeightOnly bool `` /* 133-byte string literal not displayed */
	// If set to true, it forces calibration in graph model instead of eager mode
	// when the context is in eager mode.
	ForceGraphModeCalibration bool `` /* 142-byte string literal not displayed */
	// contains filtered or unexported fields
}

Defines various options to specify and control the behavior of the quantizer. It consists of 1) Model-wise quantization configuration as a default configuration. If it is None, the default configuration is "do not quantize the model". 2) A set of supported operations. 3) Unit wise quantization precision. 4) Target hardware name. NEXT ID: 12

func (*QuantizationOptions) Descriptor deprecated

func (*QuantizationOptions) Descriptor() ([]byte, []int)

Deprecated: Use QuantizationOptions.ProtoReflect.Descriptor instead.

func (*QuantizationOptions) GetEnableLegacyWeightOnly added in v2.13.0

func (x *QuantizationOptions) GetEnableLegacyWeightOnly() bool

func (*QuantizationOptions) GetEnablePerChannelQuantization added in v2.12.0

func (x *QuantizationOptions) GetEnablePerChannelQuantization() bool

func (*QuantizationOptions) GetEnableTwoInputTensors added in v2.12.0

func (x *QuantizationOptions) GetEnableTwoInputTensors() bool

func (*QuantizationOptions) GetExperimentalEnableTpuModelSupport added in v2.13.0

func (x *QuantizationOptions) GetExperimentalEnableTpuModelSupport() bool

func (*QuantizationOptions) GetForceGraphModeCalibration added in v2.13.0

func (x *QuantizationOptions) GetForceGraphModeCalibration() bool

func (*QuantizationOptions) GetFreezeAllVariables added in v2.12.0

func (x *QuantizationOptions) GetFreezeAllVariables() *FreezeAllVariables

func (*QuantizationOptions) GetMinNumElementsForWeights added in v2.11.0

func (x *QuantizationOptions) GetMinNumElementsForWeights() int64

func (*QuantizationOptions) GetOpSet

func (x *QuantizationOptions) GetOpSet() OpSet

func (*QuantizationOptions) GetQuantizationMethod

func (x *QuantizationOptions) GetQuantizationMethod() *QuantizationMethod

func (*QuantizationOptions) GetQuantizationPrecision added in v2.11.0

func (x *QuantizationOptions) GetQuantizationPrecision() QuantizationPrecision

func (*QuantizationOptions) GetUnitWiseQuantizationPrecision added in v2.11.0

func (x *QuantizationOptions) GetUnitWiseQuantizationPrecision() []*UnitWiseQuantizationPrecision

func (*QuantizationOptions) ProtoMessage

func (*QuantizationOptions) ProtoMessage()

func (*QuantizationOptions) ProtoReflect

func (x *QuantizationOptions) ProtoReflect() protoreflect.Message

func (*QuantizationOptions) Reset

func (x *QuantizationOptions) Reset()

func (*QuantizationOptions) String

func (x *QuantizationOptions) String() string

type QuantizationPrecision added in v2.11.0

type QuantizationPrecision int32

Quantization precisions. If the specified quantization precision is not available, our quantizer needs to raise an error.

const (
	QuantizationPrecision_PRECISION_UNSPECIFIED QuantizationPrecision = 0
	// Full Precision (Do not quantize)
	QuantizationPrecision_PRECISION_FULL QuantizationPrecision = 1
	// Weight 4 bit and activation 4 bit quantization
	QuantizationPrecision_PRECISION_W4A4 QuantizationPrecision = 2
	// Weight 4 bit and activation 8 bit quantization
	QuantizationPrecision_PRECISION_W4A8 QuantizationPrecision = 3
	// Weight 8 bit and activation 8 bit quantization
	QuantizationPrecision_PRECISION_W8A8 QuantizationPrecision = 4
)

func (QuantizationPrecision) Descriptor added in v2.11.0

func (QuantizationPrecision) Enum added in v2.11.0

func (QuantizationPrecision) EnumDescriptor deprecated added in v2.11.0

func (QuantizationPrecision) EnumDescriptor() ([]byte, []int)

Deprecated: Use QuantizationPrecision.Descriptor instead.

func (QuantizationPrecision) Number added in v2.11.0

func (QuantizationPrecision) String added in v2.11.0

func (x QuantizationPrecision) String() string

func (QuantizationPrecision) Type added in v2.11.0

type UnitWiseQuantizationPrecision added in v2.11.0

type UnitWiseQuantizationPrecision struct {

	// Available quantization unit. Currently node-wise and op-wise are
	// available quantization units.
	UnitType UnitWiseQuantizationPrecision_UnitType `` /* 154-byte string literal not displayed */
	// Uniqueness isn't guaranteed across SavedModels but within each function
	// def's level, uniqueness is guaranteed. Updated
	// the configuration interfaces to reflect such circumstances.
	// If users do not need to guarantee uniqueness func_name can be omitted.
	FuncName string `protobuf:"bytes,2,opt,name=func_name,json=funcName,proto3" json:"func_name,omitempty"`
	UnitName string `protobuf:"bytes,3,opt,name=unit_name,json=unitName,proto3" json:"unit_name,omitempty"`
	// Quantization option information for the current unit.
	// TODO(b/241322587): Support specifying quantization method for each unit of
	// TF GraphDef.
	QuantizationPrecision QuantizationPrecision `` /* 176-byte string literal not displayed */
	// contains filtered or unexported fields
}

Unit (either nodes or ops at this moment) wise quantization method for mixed bit precision quantization. It contains the name of the unit, the granularity of the unit, and the quantization method for each unit. NEXT ID: 6

func (*UnitWiseQuantizationPrecision) Descriptor deprecated added in v2.11.0

func (*UnitWiseQuantizationPrecision) Descriptor() ([]byte, []int)

Deprecated: Use UnitWiseQuantizationPrecision.ProtoReflect.Descriptor instead.

func (*UnitWiseQuantizationPrecision) GetFuncName added in v2.11.0

func (x *UnitWiseQuantizationPrecision) GetFuncName() string

func (*UnitWiseQuantizationPrecision) GetQuantizationPrecision added in v2.11.0

func (x *UnitWiseQuantizationPrecision) GetQuantizationPrecision() QuantizationPrecision

func (*UnitWiseQuantizationPrecision) GetUnitName added in v2.11.0

func (x *UnitWiseQuantizationPrecision) GetUnitName() string

func (*UnitWiseQuantizationPrecision) GetUnitType added in v2.11.0

func (*UnitWiseQuantizationPrecision) ProtoMessage added in v2.11.0

func (*UnitWiseQuantizationPrecision) ProtoMessage()

func (*UnitWiseQuantizationPrecision) ProtoReflect added in v2.11.0

func (*UnitWiseQuantizationPrecision) Reset added in v2.11.0

func (x *UnitWiseQuantizationPrecision) Reset()

func (*UnitWiseQuantizationPrecision) String added in v2.11.0

type UnitWiseQuantizationPrecision_UnitType added in v2.11.0

type UnitWiseQuantizationPrecision_UnitType int32

Quantization unit granularity. NEXT ID: 3

const (
	// This should never be used. Using this will generally result in an error.
	UnitWiseQuantizationPrecision_UNIT_UNSPECIFIED UnitWiseQuantizationPrecision_UnitType = 0
	UnitWiseQuantizationPrecision_UNIT_NODE        UnitWiseQuantizationPrecision_UnitType = 1
	UnitWiseQuantizationPrecision_UNIT_OP          UnitWiseQuantizationPrecision_UnitType = 2
)

func (UnitWiseQuantizationPrecision_UnitType) Descriptor added in v2.11.0

func (UnitWiseQuantizationPrecision_UnitType) Enum added in v2.11.0

func (UnitWiseQuantizationPrecision_UnitType) EnumDescriptor deprecated added in v2.11.0

func (UnitWiseQuantizationPrecision_UnitType) EnumDescriptor() ([]byte, []int)

Deprecated: Use UnitWiseQuantizationPrecision_UnitType.Descriptor instead.

func (UnitWiseQuantizationPrecision_UnitType) Number added in v2.11.0

func (UnitWiseQuantizationPrecision_UnitType) String added in v2.11.0

func (UnitWiseQuantizationPrecision_UnitType) Type added in v2.11.0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL