Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit f89b120

Browse files
committed
Allow models to be packaged with custom chat template files
Signed-off-by: Emily Casey <[email protected]>
1 parent 89e512d commit f89b120

35 files changed

+2063
-1613
lines changed

commands/package.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,18 +74,20 @@ func newPackagedCmd() *cobra.Command {
7474
}
7575

7676
c.Flags().StringVar(&opts.ggufPath, "gguf", "", "absolute path to gguf file (required)")
77+
c.Flags().StringVar(&opts.chatTemplatePath, "chat-template", "", "absolute path to chat template file (must be Jinja format)")
7778
c.Flags().StringArrayVarP(&opts.licensePaths, "license", "l", nil, "absolute path to a license file")
7879
c.Flags().BoolVar(&opts.push, "push", false, "push to registry (if not set, the model is loaded into the Model Runner content store)")
7980
c.Flags().Uint64Var(&opts.contextSize, "context-size", 0, "context size in tokens")
8081
return c
8182
}
8283

8384
type packageOptions struct {
84-
ggufPath string
85-
licensePaths []string
86-
push bool
87-
contextSize uint64
88-
tag string
85+
chatTemplatePath string
86+
contextSize uint64
87+
ggufPath string
88+
licensePaths []string
89+
push bool
90+
tag string
8991
}
9092

9193
func packageModel(cmd *cobra.Command, opts packageOptions) error {
@@ -126,6 +128,12 @@ func packageModel(cmd *cobra.Command, opts packageOptions) error {
126128
}
127129
}
128130

131+
if opts.chatTemplatePath != "" {
132+
if pkg, err = pkg.WithChatTemplateFile(opts.chatTemplatePath); err != nil {
133+
return fmt.Errorf("add chat template file from path %q: %w", opts.chatTemplatePath, err)
134+
}
135+
}
136+
129137
if opts.push {
130138
cmd.PrintErrln("Pushing model to registry...")
131139
} else {

docs/reference/docker_model_package.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ usage: docker model package --gguf <path> [--license <path>...] [--context-size
88
pname: docker model
99
plink: docker_model.yaml
1010
options:
11+
- option: chat-template
12+
value_type: string
13+
description: absolute path to chat template file (must be Jinja format)
14+
deprecated: false
15+
hidden: false
16+
experimental: false
17+
experimentalcli: false
18+
kubernetes: false
19+
swarm: false
1120
- option: context-size
1221
value_type: uint64
1322
default_value: "0"

docs/reference/model_package.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ When packaging a sharded model --gguf should point to the first shard. All shard
88

99
| Name | Type | Default | Description |
1010
|:------------------|:--------------|:--------|:---------------------------------------------------------------------------------------|
11+
| `--chat-template` | `string` | | absolute path to chat template file (must be Jinja format) |
1112
| `--context-size` | `uint64` | `0` | context size in tokens |
1213
| `--gguf` | `string` | | absolute path to gguf file (required) |
1314
| `-l`, `--license` | `stringArray` | | absolute path to a license file |

go.mod

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ require (
1111
github.com/docker/docker v28.2.2+incompatible
1212
github.com/docker/go-connections v0.5.0
1313
github.com/docker/go-units v0.5.0
14-
github.com/docker/model-distribution v0.0.0-20250822172258-8fe9daa4a4da
14+
github.com/docker/model-distribution v0.0.0-20250918153037-7d9fc7b72b57
1515
github.com/docker/model-runner v0.0.0-20250822173738-5341c9fc2974
1616
github.com/fatih/color v1.15.0
1717
github.com/google/go-containerregistry v0.20.6
@@ -55,7 +55,7 @@ require (
5555
github.com/gogo/protobuf v1.3.2 // indirect
5656
github.com/google/uuid v1.6.0 // indirect
5757
github.com/gorilla/mux v1.8.1 // indirect
58-
github.com/gpustack/gguf-parser-go v0.14.1 // indirect
58+
github.com/gpustack/gguf-parser-go v0.22.1 // indirect
5959
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 // indirect
6060
github.com/henvic/httpretty v0.1.4 // indirect
6161
github.com/inconshreveable/mousetrap v1.1.0 // indirect
@@ -83,7 +83,6 @@ require (
8383
github.com/prometheus/common v0.65.0 // indirect
8484
github.com/prometheus/procfs v0.15.1 // indirect
8585
github.com/rivo/uniseg v0.4.7 // indirect
86-
github.com/rs/dnscache v0.0.0-20230804202142-fc85eb664529 // indirect
8786
github.com/russross/blackfriday/v2 v2.1.0 // indirect
8887
github.com/sirupsen/logrus v1.9.3 // indirect
8988
github.com/smallnest/ringbuffer v0.0.0-20241116012123-461381446e3d // indirect

go.sum

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ github.com/docker/go-metrics v0.0.1/go.mod h1:cG1hvH2utMXtqgqqYE9plW6lDxS3/5ayHz
7878
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
7979
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
8080
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7/go.mod h1:cyGadeNEkKy96OOhEzfZl+yxihPEzKnqJwvfuSUqbZE=
81-
github.com/docker/model-distribution v0.0.0-20250822172258-8fe9daa4a4da h1:ml99WBfcLnsy1frXQR4X+5WAC0DoGtwZyGoU/xBsDQM=
82-
github.com/docker/model-distribution v0.0.0-20250822172258-8fe9daa4a4da/go.mod h1:dThpO9JoG5Px3i+rTluAeZcqLGw8C0qepuEL4gL2o/c=
81+
github.com/docker/model-distribution v0.0.0-20250918153037-7d9fc7b72b57 h1:WHiPO9UmO5v97T3ksQUA2SbYVkTdUCSFobznegL97kk=
82+
github.com/docker/model-distribution v0.0.0-20250918153037-7d9fc7b72b57/go.mod h1:bV1RH2e79nTwOW38GoMU9UO8gpZVLH9+cZeEeR4wSeE=
8383
github.com/docker/model-runner v0.0.0-20250822173738-5341c9fc2974 h1:/uF17tBEtsE6T2Xgg4cgrrqNcQ02gY5Lp98je+2K0nQ=
8484
github.com/docker/model-runner v0.0.0-20250822173738-5341c9fc2974/go.mod h1:1Q2QRB5vob542x6P5pQXlGTYs5bYPxNG6ePcjTndA0A=
8585
github.com/dvsekhvalnov/jose2go v0.0.0-20170216131308-f21a8cedbbae/go.mod h1:7BvyPhdbLxMXIYTFPLsyJRFMsKmOZnQmzh6Gb+uquuM=
@@ -128,8 +128,8 @@ github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
128128
github.com/gorilla/mux v1.7.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
129129
github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY=
130130
github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ=
131-
github.com/gpustack/gguf-parser-go v0.14.1 h1:tmz2eTnSEFfE52V10FESqo9oAUquZ6JKQFntWC/wrEg=
132-
github.com/gpustack/gguf-parser-go v0.14.1/go.mod h1:GvHh1Kvvq5ojCOsJ5UpwiJJmIjFw3Qk5cW7R+CZ3IJo=
131+
github.com/gpustack/gguf-parser-go v0.22.1 h1:FRnEDWqT0Rcplr/R9ctCRSN2+3DhVsf6dnR5/i9JA4E=
132+
github.com/gpustack/gguf-parser-go v0.22.1/go.mod h1:y4TwTtDqFWTK+xvprOjRUh+dowgU2TKCX37vRKvGiZ0=
133133
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 h1:e9Rjr40Z98/clHv5Yg79Is0NtosR5LXRvdr7o/6NwbA=
134134
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1/go.mod h1:tIxuGz/9mpox++sgp9fJjHO0+q1X9/UOWd798aAm22M=
135135
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
@@ -241,8 +241,6 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
241241
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
242242
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
243243
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
244-
github.com/rs/dnscache v0.0.0-20230804202142-fc85eb664529 h1:18kd+8ZUlt/ARXhljq+14TwAoKa61q6dX8jtwOf6DH8=
245-
github.com/rs/dnscache v0.0.0-20230804202142-fc85eb664529/go.mod h1:qe5TWALJ8/a1Lqznoc5BDHpYX/8HU60Hm2AwRmqzxqA=
246244
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
247245
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
248246
github.com/sirupsen/logrus v1.0.6/go.mod h1:pMByvHTf9Beacp5x1UXfOR9xyW/9antXMhjMPG0dEzc=

vendor/github.com/docker/model-distribution/builder/builder.go

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/model-distribution/internal/bundle/bundle.go

Lines changed: 13 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/model-distribution/internal/bundle/parse.go

Lines changed: 23 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/model-distribution/internal/bundle/unpack.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/model-distribution/internal/partial/partial.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)