Skip to content

Redesign attribute.go #42

Open
Open
@wangkuiyi

Description

@wangkuiyi

Declare Attributes

Currently, users write the following code to declare attributes:

var distributedTrainingAttributes = attribute.Dictionary{
	"train.num_ps":        {attribute.Int, 0, "", nil},
	"train.num_workers":   {attribute.Int, 1, "", nil},
	"train.worker_cpu":    {attribute.Int, 400, "", nil},
}

This forces us to expose types like attribute.Description which should be internal. Also, this exposes constants like attribute.Int, which should be hidden as well.

Following the design of https://golang.org/pkg/flag/, the declaration should be

var distributedTrainingAttributes = attribute.NewDictionary{).
	Int("train.num_ps", 0, "", nil),
	Int("train.num_workers", 1, "", nil),
	Int("train.worker_cpu", 400, "", nil),
}

We must be very careful about the abuse of interface {}. In the current API, users can passing value as an interface {} type, which might not match the specified type.

Also, users can pass in any reflect.Type as the type, not necessarily chosen from the pre-defined list.

Changing to Int("train.num_pos", 0, ...) makes the compiler checks the type and value are matched.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions