kaggle

package
v0.0.0-...-83792b2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package kaggle loads Gemma weights into tensors along with the matching metadata, after they have been downloaded from kaggle and converted using the included cmd/convert_checkpoint.py.

Index

Constants

View Source
const (
	MetadataFileName = "_METADATA"
	KeyUseZarr3      = "use_zarr3"
	KeyTreeMetadata  = "tree_metadata"
	KeyKeyMetadata   = "key_metadata"
	KeyValueMetadata = "value_metadata"
)
View Source
const (
	AggregateFileName = "checkpoint"

	// OCDBTManifestFileName indicates usage of "Orbax Consistent Distributed Backend Tree" (OCDBT).
	OCDBTManifestFileName = "manifest.ocdbt"
)

Variables

This section is empty.

Functions

func ParamNames

func ParamNames(metadata *trees.Tree[*Metadata]) *trees.Tree[string]

ParamNames convert metadata to the paramNames (?? not sure where in Gemma this is sued)

func PyReadAggregate

func PyReadAggregate(checkpointDir string) (results any, err error)

PyReadAggregate of Python checkpoint. Not used by Gemma v2.

func PyReadParamInfo

func PyReadParamInfo(checkpointDir string) *trees.Tree[*PyParamInfo]

func ReadConvertedWeights

func ReadConvertedWeights(ctx *context.Context, checkpointDir string) error

ReadConvertedWeights from checkpointDir (under the "raw/" subdirectory). It will read the weights and shape converted by the `convert_checkpoint.py` script (see github.com/gomlx/gemma repository, under cmd/convert_checkpoint.py) and set them in the given context, under its current scope.

func ReadConvertedWeightsToTree

func ReadConvertedWeightsToTree(checkpointDir string) (tree *trees.Tree[*tensors.Tensor], err error)

ReadConvertedWeightsToTree from checkpointDir (under the "raw/" subdirectory). It will read the weights and shape converted by the `convert_checkpoint.py` script (see github.com/gomlx/gemma repository, under cmd/convert_checkpoint.py)

It returns a tree of tensors, with the path matching those of the original Jax checkpoint.

func ReadMetadata

func ReadMetadata(checkpointDir string) (tree *trees.Tree[*Metadata], err error)

ReadMetadata returns the metadata loaded from the given directory in the form of a tree.

func UploadWeightsToContext

func UploadWeightsToContext(ctx *context.Context, weights *trees.Tree[*tensors.Tensor])

UploadWeightsToContext creates variables corresponding to the weights. It returns the ctx given, with the variables set.

It's tightly coupled with the model building functions in this package. Meaning the modeling must match the naming here.

Types

type Metadata

type Metadata struct {
	KeyPath []string

	KeyToKeyType    map[string]MetadataKeyType
	ValueType       string
	SkipDeserialize bool
}

Metadata of one checkpoint entry (usually weights or embedding tables of model)

func (*Metadata) String

func (m *Metadata) String() string

String implements fmt.Stringer.

type MetadataKeyType

type MetadataKeyType int
const (
	KeyTypeSequence MetadataKeyType = 1
	KeyTypeDict                     = 2
)

type PyParamInfo

type PyParamInfo struct {
	Name, Path      string
	SkipDeserialize bool
}

Jump to

Keyboard shortcuts

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