Revert "only forward some env vars"

This reverts commit ce3b212d12.
This commit is contained in:
jmorganca 2024-05-10 22:53:21 -07:00
parent 1e1634daca
commit 92ca2cca95

View file

@ -288,26 +288,32 @@ func NewLlamaServer(gpus gpu.GpuInfoList, model string, ggml *GGML, adapters, pr
done: make(chan error, 1), done: make(chan error, 1),
} }
s.cmd.Env = os.Environ()
s.cmd.Stdout = os.Stdout s.cmd.Stdout = os.Stdout
s.cmd.Stderr = s.status s.cmd.Stderr = s.status
if v := strings.Join(libraryPaths, string(filepath.ListSeparator)); v != "" { visibleDevicesEnv, visibleDevicesEnvVal := gpu.GpuInfoList(gpus).GetVisibleDevicesEnv()
s.cmd.Env = append(s.cmd.Env, pathEnv+"="+v) pathEnvVal := strings.Join(libraryPaths, string(filepath.ListSeparator))
}
if k, v := gpu.GpuInfoList(gpus).GetVisibleDevicesEnv(); k != "" { // Update or add the path and visible devices variable with our adjusted version
s.cmd.Env = append(s.cmd.Env, k+"="+v) pathNeeded := true
} devicesNeeded := visibleDevicesEnv != ""
for i := range s.cmd.Env {
for _, ev := range os.Environ() { cmp := strings.SplitN(s.cmd.Env[i], "=", 2)
if strings.HasPrefix(ev, "CUDA_") || if strings.EqualFold(cmp[0], pathEnv) {
strings.HasPrefix(ev, "ROCM_") || s.cmd.Env[i] = pathEnv + "=" + pathEnvVal
strings.HasPrefix(ev, "HIP_") || pathNeeded = false
strings.HasPrefix(ev, "HSA_") || } else if devicesNeeded && strings.EqualFold(cmp[0], visibleDevicesEnv) {
strings.HasPrefix(ev, "GGML_") { s.cmd.Env[i] = visibleDevicesEnv + "=" + visibleDevicesEnvVal
s.cmd.Env = append(s.cmd.Env, ev) devicesNeeded = false
} }
} }
if pathNeeded {
s.cmd.Env = append(s.cmd.Env, pathEnv+"="+pathEnvVal)
}
if devicesNeeded {
s.cmd.Env = append(s.cmd.Env, visibleDevicesEnv+"="+visibleDevicesEnvVal)
}
slog.Info("starting llama server", "cmd", s.cmd.String()) slog.Info("starting llama server", "cmd", s.cmd.String())
// Log at debug as the environment is inherited and might contain sensitive information // Log at debug as the environment is inherited and might contain sensitive information