Skip to content

Commit

Permalink
fix: experiment config slots to comply with constraint max slots
Browse files Browse the repository at this point in the history
  • Loading branch information
amandavialva01 committed Oct 15, 2024
1 parent 2ef2f12 commit 655f635
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
6 changes: 3 additions & 3 deletions master/internal/configpolicy/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,9 @@ func checkConstraintConflicts(constraints *model.Constraints, maxSlots, slots, p
if maxSlots != nil && *constraints.ResourceConstraints.MaxSlots != *maxSlots {
return fmt.Errorf("invariant config & constraints are trying to set the max slots")
}
if slots != nil && *constraints.ResourceConstraints.MaxSlots > *slots {
return fmt.Errorf("invariant config & constraints are attempting to set an invalid max slot123: %v vs %v",
*constraints.ResourceConstraints.MaxSlots, *slots)
if slots != nil && *constraints.ResourceConstraints.MaxSlots < *slots {
return fmt.Errorf("invariant config has %v slots per trial. violates constraints max slots of %v",
*slots, *constraints.ResourceConstraints.MaxSlots)
}

return nil
Expand Down
43 changes: 43 additions & 0 deletions master/internal/configpolicy/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"gotest.tools/assert"

"github.com/determined-ai/determined/master/pkg/model"
"github.com/determined-ai/determined/master/pkg/ptrs"
"github.com/determined-ai/determined/master/pkg/schemas/expconf"
)

Expand Down Expand Up @@ -309,3 +310,45 @@ func TestUnmarshalJSONNTSC(t *testing.T) {
})
}
}

func TestCheckConstraintsConflicts(t *testing.T) {
constraints := &model.Constraints{
ResourceConstraints: &model.ResourceConstraints{
MaxSlots: ptrs.Ptr(10),
},
PriorityLimit: ptrs.Ptr(50),
}
t.Run("max_slots differs to high", func(t *testing.T) {
err := checkConstraintConflicts(constraints, ptrs.Ptr(11), ptrs.Ptr(5), nil)
require.Error(t, err)
})
t.Run("max_slots differs to low", func(t *testing.T) {
err := checkConstraintConflicts(constraints, ptrs.Ptr(9), ptrs.Ptr(5), nil)
require.Error(t, err)
})

t.Run("slots_per_trial too high", func(t *testing.T) {
err := checkConstraintConflicts(constraints, ptrs.Ptr(5), ptrs.Ptr(11), nil)
require.Error(t, err)
})

t.Run("slots_per_trial within range", func(t *testing.T) {
err := checkConstraintConflicts(constraints, ptrs.Ptr(10), ptrs.Ptr(8), nil)
require.NoError(t, err)
})

t.Run("priority differs too high", func(t *testing.T) {
err := checkConstraintConflicts(constraints, nil, nil, ptrs.Ptr(100))
require.Error(t, err)
})

t.Run("priority differs too low", func(t *testing.T) {
err := checkConstraintConflicts(constraints, nil, nil, ptrs.Ptr(10))
require.Error(t, err)
})

t.Run("all comply", func(t *testing.T) {
err := checkConstraintConflicts(constraints, ptrs.Ptr(10), ptrs.Ptr(10), ptrs.Ptr(50))
require.NoError(t, err)
})
}

0 comments on commit 655f635

Please sign in to comment.