88 "io/fs"
99 "net/http"
1010 "os"
11+ "os/exec"
1112 "path/filepath"
1213 "strings"
1314
@@ -45,14 +46,17 @@ type vLLM struct {
4546 customBinaryPath string
4647 // registryMirrors is the list of registry mirrors to try before registry-1.docker.io.
4748 registryMirrors []string
49+ // commandModifier, if non-nil, is applied to the server process before it starts.
50+ commandModifier func (* exec.Cmd )
4851}
4952
5053// Options holds the configuration for the unified vLLM backend constructor.
5154type Options struct {
52- Config * Config // Linux-only: extra vllm args (nil = defaults)
53- LinuxBinaryPath string // Linux: custom vllm binary path
54- MetalPythonPath string // macOS ARM64: custom python path
55- RegistryMirrors []string // registry mirrors tried before registry-1.docker.io
55+ Config * Config // Linux-only: extra vllm args (nil = defaults)
56+ LinuxBinaryPath string // Linux: custom vllm binary path
57+ MetalPythonPath string // macOS ARM64: custom python path
58+ RegistryMirrors []string // registry mirrors tried before registry-1.docker.io
59+ CommandModifier func (* exec.Cmd ) // applied to the server process before it starts
5660}
5761
5862// New creates the appropriate vLLM backend for the current platform.
@@ -61,9 +65,9 @@ type Options struct {
6165// methods return errors.
6266func New (log logging.Logger , modelManager * models.Manager , serverLog logging.Logger , opts Options ) (inference.Backend , error ) {
6367 if platform .SupportsVLLMMetal () {
64- return newMetal (log , modelManager , serverLog , opts .MetalPythonPath , opts .RegistryMirrors )
68+ return newMetal (log , modelManager , serverLog , opts .MetalPythonPath , opts .RegistryMirrors , opts . CommandModifier )
6569 }
66- return newLinux (log , modelManager , serverLog , opts .Config , opts .LinuxBinaryPath , opts .RegistryMirrors )
70+ return newLinux (log , modelManager , serverLog , opts .Config , opts .LinuxBinaryPath , opts .RegistryMirrors , opts . CommandModifier )
6771}
6872
6973// NeedsDeferredInstall reports whether vllm on the current platform
@@ -74,7 +78,7 @@ func NeedsDeferredInstall() bool {
7478
7579// newLinux creates a new Linux vLLM-based backend.
7680// customBinaryPath is an optional path to a custom vllm binary; if empty, the default path is used.
77- func newLinux (log logging.Logger , modelManager * models.Manager , serverLog logging.Logger , conf * Config , customBinaryPath string , registryMirrors []string ) (inference.Backend , error ) {
81+ func newLinux (log logging.Logger , modelManager * models.Manager , serverLog logging.Logger , conf * Config , customBinaryPath string , registryMirrors []string , commandModifier func ( * exec. Cmd ) ) (inference.Backend , error ) {
7882 // If no config is provided, use the default configuration
7983 if conf == nil {
8084 conf = NewDefaultVLLMConfig ()
@@ -88,6 +92,7 @@ func newLinux(log logging.Logger, modelManager *models.Manager, serverLog loggin
8892 status : inference .FormatNotInstalled ("" ),
8993 customBinaryPath : customBinaryPath ,
9094 registryMirrors : registryMirrors ,
95+ commandModifier : commandModifier ,
9196 }, nil
9297}
9398
@@ -189,6 +194,7 @@ func (v *vLLM) Run(ctx context.Context, socket, model string, modelRef string, m
189194 Args : args ,
190195 Logger : v .log ,
191196 ServerLogWriter : logging .NewWriter (v .serverLog ),
197+ CommandModifier : v .commandModifier ,
192198 })
193199}
194200
0 commit comments