Skip to content

Commit 7c611ce

Browse files
committed
fix: change context size and reasoning budget types from uint64 to int32
1 parent 2709ecd commit 7c611ce

File tree

22 files changed

+164
-362
lines changed

22 files changed

+164
-362
lines changed

cmd/cli/commands/compose.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func newUpCommand() *cobra.Command {
6666
return err
6767
}
6868

69-
if ctxSize > 0 {
69+
if cmd.Flags().Changed("context-size") {
7070
sendInfo(fmt.Sprintf("Setting context size to %d", ctxSize))
7171
}
7272

@@ -82,12 +82,18 @@ func newUpCommand() *cobra.Command {
8282
}
8383

8484
for _, model := range models {
85+
configuration := inference.BackendConfiguration{
86+
Speculative: speculativeConfig,
87+
}
88+
if cmd.Flags().Changed("context-size") {
89+
//TODO is the context size the same for all models?
90+
v := int32(ctxSize)
91+
configuration.ContextSize = &v
92+
}
93+
8594
if err := desktopClient.ConfigureBackend(scheduling.ConfigureRequest{
86-
Model: model,
87-
BackendConfiguration: inference.BackendConfiguration{
88-
ContextSize: ctxSize,
89-
Speculative: speculativeConfig,
90-
},
95+
Model: model,
96+
BackendConfiguration: configuration,
9197
}); err != nil {
9298
configErrFmtString := "failed to configure backend for model %s with context-size %d"
9399
_ = sendErrorf(configErrFmtString+": %v", model, ctxSize, err)

cmd/cli/commands/configure.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func newConfigureCmd() *cobra.Command {
1717
var numTokens int
1818
var minAcceptanceRate float64
1919
var hfOverrides string
20+
var contextSize int64
2021
var reasoningBudget int64
2122

2223
c := &cobra.Command{
@@ -34,6 +35,10 @@ func newConfigureCmd() *cobra.Command {
3435
return nil
3536
},
3637
RunE: func(cmd *cobra.Command, args []string) error {
38+
if cmd.Flags().Changed("context-size") {
39+
v := int32(contextSize)
40+
opts.ContextSize = &v
41+
}
3742
// Build the speculative config if any speculative flags are set
3843
if draftModel != "" || numTokens > 0 || minAcceptanceRate > 0 {
3944
opts.Speculative = &inference.SpeculativeDecodingConfig{
@@ -64,14 +69,15 @@ func newConfigureCmd() *cobra.Command {
6469
if opts.LlamaCpp == nil {
6570
opts.LlamaCpp = &inference.LlamaCppConfig{}
6671
}
67-
opts.LlamaCpp.ReasoningBudget = &reasoningBudget
72+
v := int32(reasoningBudget)
73+
opts.LlamaCpp.ReasoningBudget = &v
6874
}
6975
return desktopClient.ConfigureBackend(opts)
7076
},
7177
ValidArgsFunction: completion.ModelNames(getDesktopClient, -1),
7278
}
7379

74-
c.Flags().Int64Var(&opts.ContextSize, "context-size", -1, "context size (in tokens)")
80+
c.Flags().Int64Var(&contextSize, "context-size", 0, "context size (in tokens)")
7581
c.Flags().StringVar(&draftModel, "speculative-draft-model", "", "draft model for speculative decoding")
7682
c.Flags().IntVar(&numTokens, "speculative-num-tokens", 0, "number of tokens to predict speculatively")
7783
c.Flags().Float64Var(&minAcceptanceRate, "speculative-min-acceptance-rate", 0, "minimum acceptance rate for speculative decoding")

cmd/cli/commands/package.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,9 @@ func packageModel(cmd *cobra.Command, opts packageOptions) error {
284284
distClient := initResult.distClient
285285

286286
// Set context size
287-
if opts.contextSize > 0 {
287+
if cmd.Flags().Changed("context-size") {
288288
cmd.PrintErrf("Setting context size %d\n", opts.contextSize)
289-
pkg = pkg.WithContextSize(opts.contextSize)
289+
pkg = pkg.WithContextSize(int32(opts.contextSize))
290290
}
291291

292292
// Add license files

cmd/mdltool/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func cmdPackage(args []string) int {
321321

322322
if contextSize > 0 {
323323
fmt.Println("Setting context size:", contextSize)
324-
b = b.WithContextSize(contextSize)
324+
b = b.WithContextSize(int32(contextSize))
325325
}
326326

327327
if mmproj != "" {

pkg/distribution/builder/builder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (b *Builder) WithLicense(path string) (*Builder, error) {
6767
}, nil
6868
}
6969

70-
func (b *Builder) WithContextSize(size uint64) *Builder {
70+
func (b *Builder) WithContextSize(size int32) *Builder {
7171
return &Builder{
7272
model: mutate.ContextSize(b.model, size),
7373
originalLayers: b.originalLayers,

pkg/distribution/internal/mutate/model.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type model struct {
1616
base types.ModelArtifact
1717
appended []v1.Layer
1818
configMediaType ggcr.MediaType
19-
contextSize *uint64
19+
contextSize *int32
2020
}
2121

2222
func (m *model) Descriptor() (types.Descriptor, error) {

pkg/distribution/internal/mutate/mutate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func ConfigMediaType(mdl types.ModelArtifact, mt ggcr.MediaType) types.ModelArti
2121
}
2222
}
2323

24-
func ContextSize(mdl types.ModelArtifact, cs uint64) types.ModelArtifact {
24+
func ContextSize(mdl types.ModelArtifact, cs int32) types.ModelArtifact {
2525
return &model{
2626
base: mdl,
2727
contextSize: &cs,

pkg/distribution/internal/mutate/mutate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestContextSize(t *testing.T) {
108108
if cfg2.ContextSize == nil {
109109
t.Fatal("Expected non-nil context")
110110
}
111-
if *cfg2.ContextSize != uint64(2096) {
111+
if *cfg2.ContextSize != 2096 {
112112
t.Fatalf("Expected context size of 2096 got %d", *cfg2.ContextSize)
113113
}
114114
}

pkg/distribution/internal/store/store_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ func TestWriteLightweight(t *testing.T) {
10401040
}
10411041

10421042
// Modify the model's config by changing context size
1043-
newContextSize := uint64(4096)
1043+
newContextSize := int32(4096)
10441044
modifiedModel := mutate.ContextSize(baseModel, newContextSize)
10451045

10461046
// Use WriteLightweight to write the modified model
@@ -1135,7 +1135,7 @@ func TestWriteLightweight(t *testing.T) {
11351135
}
11361136

11371137
// Create a variant with different config
1138-
newContextSize := uint64(8192)
1138+
newContextSize := int32(8192)
11391139
variant := mutate.ContextSize(baseModel, newContextSize)
11401140

11411141
// Use WriteLightweight with multiple tags
@@ -1213,7 +1213,7 @@ func TestWriteLightweight(t *testing.T) {
12131213
}
12141214

12151215
// Create a variant with different context size
1216-
newContextSize := uint64(2048)
1216+
newContextSize := int32(2048)
12171217
variant := mutate.ContextSize(baseModel, newContextSize)
12181218

12191219
// Use WriteLightweight for the variant
@@ -1271,7 +1271,7 @@ func TestWriteLightweight(t *testing.T) {
12711271

12721272
// Create multiple variants using WriteLightweight
12731273
for i := 1; i <= 3; i++ {
1274-
contextSize := uint64(1024 * i)
1274+
contextSize := int32(1024 * i)
12751275
variant := mutate.ContextSize(baseModel, contextSize)
12761276
tag := fmt.Sprintf("integrity-test:variant%d", i)
12771277
if err := s.WriteLightweight(variant, []string{tag}); err != nil {

pkg/distribution/types/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ type Config struct {
6767
Size string `json:"size,omitempty"`
6868
GGUF map[string]string `json:"gguf,omitempty"`
6969
Safetensors map[string]string `json:"safetensors,omitempty"`
70-
ContextSize *uint64 `json:"context_size,omitempty"`
70+
ContextSize *int32 `json:"context_size,omitempty"`
7171
}
7272

7373
// Descriptor provides metadata about the provenance of the model.

0 commit comments

Comments
 (0)