Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .nextchanges/air/list-filter-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Support full workspace accelerator types in `air list` filters while preserving family matching, and reject invalid filter values. ([#7515](https://github.com/databricks/cli/pull/7515))
6 changes: 5 additions & 1 deletion acceptance/air/help/output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ List active runs for the current user.
Filters:
Use --filter KEY=VALUE per condition. A run must match every condition.

accelerator_type Accelerator type, such as A10 or H100.
accelerator_type Accelerator family or full YAML type. Examples:
A10, H100, GPU_1xA10, GPU_8xH100.
Workspace types: databricks air run -h config.compute.accelerator_type
experiment Case-insensitive glob matched against the experiment name.
num_accelerators Total GPU count.
user Run creator identifier.
Expand All @@ -63,6 +65,8 @@ Usage:
Examples:
databricks air list --filter accelerator_type=H100

databricks air list --filter accelerator_type=GPU_8xH100

databricks air list --all-status \
--filter 'experiment=qwen*' \
--filter num_accelerators=8 \
Expand Down
49 changes: 41 additions & 8 deletions cmd/air/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,16 @@ func newListCommand() *cobra.Command {
Filters:
Use --filter KEY=VALUE per condition. A run must match every condition.

accelerator_type Accelerator type, such as A10 or H100.
accelerator_type Accelerator family or full YAML type. Examples:
A10, H100, GPU_1xA10, GPU_8xH100.
Workspace types: databricks air run -h config.compute.accelerator_type
experiment Case-insensitive glob matched against the experiment name.
num_accelerators Total GPU count.
user Run creator identifier.`,
Example: ` databricks air list --filter accelerator_type=H100

databricks air list --filter accelerator_type=GPU_8xH100

databricks air list --all-status \
--filter 'experiment=qwen*' \
--filter num_accelerators=8 \
Expand All @@ -127,6 +131,9 @@ Filters:
if err != nil {
return err
}
if f.AcceleratorType != "" {
configureAcceleratorFilter(&f)
}

// An explicit user= filter wins; otherwise default to the current user
// unless --all-users is set. runs/list has no creator param, so the
Expand Down Expand Up @@ -161,6 +168,11 @@ Filters:
limit: limit,
workspaceID: workspaceID,
})
if f.AcceleratorType != "" {
fetcher.validateEmpty = func() error {
return validateEmptyAcceleratorFilter(ctx, w, f.AcceleratorType)
}
}

// JSON prints the newest `limit` runs once. Text renders the table:
// navigable in a terminal (paging in older runs on demand), printed once
Expand All @@ -179,6 +191,15 @@ Filters:
return cmd
}

func validateEmptyAcceleratorFilter(ctx context.Context, w *databricks.WorkspaceClient, value string) error {
options, err := listWorkspaceComputeOptions(ctx, w)
if err != nil {
log.Debugf(ctx, "air list: could not validate accelerator filter against workspace compute options: %v", err)
return fmt.Errorf("no runs matched --filter accelerator_type=%q\nRetry or run 'databricks air run -h config.compute.accelerator_type' to check available types", value)
}
return validateAcceleratorFilter(value, options)
}

// listStrategy is a source of matching runs, pulled in batches. Two implement it:
// jobsScanStrategy pages runs/list; indexStrategy hydrates the AiTrainingService
// index. The fetcher wraps whichever is chosen.
Expand All @@ -195,13 +216,16 @@ type listStrategy interface {
// the interactive table's lazy paging. It wraps a listStrategy and adds the
// shared tail: MLflow enrichment (text only) and row projection.
type runFetcher struct {
ctx context.Context
w *databricks.WorkspaceClient
fetchMLflow bool
strategy listStrategy
workspaceID int64

exhausted bool
ctx context.Context
w *databricks.WorkspaceClient
fetchMLflow bool
strategy listStrategy
workspaceID int64
validateEmpty func() error

exhausted bool
matchedAny bool
validatedEmpty bool
}

func newRunFetcher(ctx context.Context, w *databricks.WorkspaceClient, q listQuery) *runFetcher {
Expand Down Expand Up @@ -241,6 +265,15 @@ func (f *runFetcher) next(want int) ([]listRow, error) {
return nil, err
}
f.exhausted = f.strategy.done()
if len(entries) > 0 {
f.matchedAny = true
}
if len(entries) == 0 && f.exhausted && !f.matchedAny && f.validateEmpty != nil && !f.validatedEmpty {
f.validatedEmpty = true
if err := f.validateEmpty(); err != nil {
return nil, err
}
}

// MLflow links appear only in the text table, so the per-run get-output
// lookups are skipped for JSON output (which omits the column anyway).
Expand Down
114 changes: 108 additions & 6 deletions cmd/air/list_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package aircmd
import (
"fmt"
"path"
"slices"
"strconv"
"strings"

Expand All @@ -26,9 +27,14 @@ type listFilters struct {
User string
// Experiment is a case-insensitive glob
Experiment string
// AcceleratorType is a case-insensitive substring matched against the
// display GPU name (e.g. "H100").
// AcceleratorType is the user-provided family or full type.
AcceleratorType string
// ResolvedAcceleratorType is the canonical-looking user input used for an
// exact full-type match against runs.
ResolvedAcceleratorType string
// AcceleratorFamilyMatch preserves the legacy case-insensitive substring
// match against the display GPU family.
AcceleratorFamilyMatch bool
// NumAccelerators is an exact match against the GPU count.
NumAccelerators *int
}
Expand All @@ -40,10 +46,20 @@ func parseListFilters(raw []string) (listFilters, error) {
if !ok || key == "" {
return listFilters{}, fmt.Errorf("invalid --filter %q: expected KEY=VALUE", item)
}
if !slices.Contains(supportedFilterKeys, key) {
return listFilters{}, fmt.Errorf("unsupported --filter key %q: supported keys are %s", key, strings.Join(supportedFilterKeys, ", "))
}
value = strings.TrimSpace(value)
if value == "" {
return listFilters{}, fmt.Errorf("invalid --filter %s=%q: value cannot be empty", key, value)
}
switch key {
case "user":
f.User = value
case "experiment":
if _, err := path.Match(value, ""); err != nil {
return listFilters{}, fmt.Errorf("invalid --filter experiment=%q: invalid glob pattern: %w", value, err)
}
f.Experiment = value
case "accelerator_type":
f.AcceleratorType = value
Expand All @@ -53,13 +69,95 @@ func parseListFilters(raw []string) (listFilters, error) {
return listFilters{}, fmt.Errorf("invalid --filter num_accelerators=%q: must be a positive integer", value)
}
f.NumAccelerators = &n
default:
return listFilters{}, fmt.Errorf("unsupported --filter key %q: supported keys are %s", key, strings.Join(supportedFilterKeys, ", "))
}
}
return f, nil
}

// configureAcceleratorFilter selects exact full-type matching for YAML-style
// values and preserves legacy family substring matching for everything else.
func configureAcceleratorFilter(f *listFilters) {
if strings.HasPrefix(strings.ToUpper(f.AcceleratorType), "GPU_") {
f.ResolvedAcceleratorType = f.AcceleratorType
return
}
f.AcceleratorFamilyMatch = true
}

// validateAcceleratorFilter checks a filter that produced no runs against the
// accelerator types currently available in the workspace.
func validateAcceleratorFilter(value string, options []computeOption) error {
for _, option := range options {
if strings.EqualFold(value, option.HardwareAccelerator) {
return nil
}
}

if !strings.HasPrefix(strings.ToUpper(value), "GPU_") {
for _, option := range options {
family := acceleratorFamily(option.HardwareAccelerator)
if strings.Contains(strings.ToLower(family), strings.ToLower(value)) {
return nil
}
}
}
if fullType := suggestedAcceleratorType(value, options); fullType != "" {
return fmt.Errorf("invalid --filter accelerator_type=%q: use %q", value, fullType)
}
return fmt.Errorf("invalid --filter accelerator_type=%q: %s", value, validAcceleratorFilterHint(options))
}

// acceleratorFamily extracts the hardware family from a canonical type without
// a client-side type list.
func acceleratorFamily(acceleratorType string) string {
prefix, family, ok := strings.Cut(acceleratorShorthand(acceleratorType), "x")
if ok {
if _, err := strconv.Atoi(prefix); err == nil && family != "" {
return family
}
}
return acceleratorType
}

func acceleratorShorthand(acceleratorType string) string {
return strings.TrimPrefix(acceleratorType, "GPU_")
}

func acceleratorRunFamily(acceleratorType string) string {
family := acceleratorFamily(acceleratorType)
if family != acceleratorType {
return family
}
return gpuDisplayName(acceleratorType)
}

func suggestedAcceleratorType(value string, options []computeOption) string {
compact := strings.Join(strings.Fields(value), "")
for _, option := range options {
if strings.EqualFold(compact, acceleratorShorthand(option.HardwareAccelerator)) {
return option.HardwareAccelerator
}
}
return ""
}

func validAcceleratorFilterHint(options []computeOption) string {
var families, fullTypes []string
for _, option := range options {
family := acceleratorFamily(option.HardwareAccelerator)
if !slices.ContainsFunc(families, func(v string) bool { return strings.EqualFold(v, family) }) {
families = append(families, family)
}
fullTypes = append(fullTypes, option.HardwareAccelerator)
}
if len(fullTypes) == 0 {
return "no accelerator types are available in this workspace"
}
parts := []string{"families (" + strings.Join(families, ", ") + ")"}
parts = append(parts, "full types ("+strings.Join(fullTypes, ", ")+")")
return "valid values for this workspace include " + strings.Join(parts, ", ")
}

// filterFields are the task-filter inputs, cached alongside the row so a cache
// hit can be re-filtered without re-fetching the run.
type filterFields struct {
Expand Down Expand Up @@ -95,8 +193,12 @@ func (f listFilters) matchesFields(fields filterFields) bool {
}

if f.AcceleratorType != "" {
display := strings.ToLower(gpuDisplayName(fields.GPUType))
if !strings.Contains(display, strings.ToLower(f.AcceleratorType)) {
if f.AcceleratorFamilyMatch {
family := strings.ToLower(acceleratorRunFamily(fields.GPUType))
if !strings.Contains(family, strings.ToLower(f.AcceleratorType)) {
return false
}
} else if !strings.EqualFold(f.ResolvedAcceleratorType, fields.GPUType) {
return false
}
}
Expand Down
Loading
Loading