Skip to content

Commit

Permalink
Enable windows error dialog for subprocess startup
Browse files Browse the repository at this point in the history
Make sure if something goes wrong spawning the process, the user gets
enough info to be able to try to self correct, or at least file a bug
with details so we can fix it.  Once the process starts, we immediately
change back to the recommended setting to prevent the blocking dialog.
This ensures if the model fails to load (OOM, unsupported model type,
etc.) the process will exit quickly and we can scan the stdout/stderr
of the subprocess for the reason to report via API.
  • Loading branch information
dhiltgen committed Jul 22, 2024
1 parent c064823 commit e12fff8
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 2 deletions.
4 changes: 4 additions & 0 deletions llm/ext_server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

#if defined(_WIN32)
#include <windows.h>
#include <errhandlingapi.h>
#endif

#include <cstddef>
Expand Down Expand Up @@ -2737,6 +2738,9 @@ int wmain(int argc, wchar_t **wargv) {
for (int i = 0; i < argc; ++i) {
argv[i] = wchar_to_char(wargv[i]);
}

// Adjust error mode to avoid error dialog after we start.
SetErrorMode(SEM_FAILCRITICALERRORS);
#else
int main(int argc, char **argv) {
#endif
Expand Down
3 changes: 3 additions & 0 deletions llm/llm_darwin_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package llm

import (
"embed"
"syscall"
)

//go:embed build/darwin/x86_64/*/bin/*
var libEmbed embed.FS

var LlamaServerSysProcAttr = &syscall.SysProcAttr{}
3 changes: 3 additions & 0 deletions llm/llm_darwin_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package llm

import (
"embed"
"syscall"
)

//go:embed build/darwin/arm64/*/bin/*
var libEmbed embed.FS

var LlamaServerSysProcAttr = &syscall.SysProcAttr{}
7 changes: 6 additions & 1 deletion llm/llm_linux.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package llm

import "embed"
import (
"embed"
"syscall"
)

//go:embed build/linux/*/*/bin/*
var libEmbed embed.FS

var LlamaServerSysProcAttr = &syscall.SysProcAttr{}
16 changes: 15 additions & 1 deletion llm/llm_windows.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
package llm

import "embed"
import (
"embed"
"syscall"
)

// unused on windows
var libEmbed embed.FS

const CREATE_DEFAULT_ERROR_MODE = 0x04000000

var LlamaServerSysProcAttr = &syscall.SysProcAttr{
// Wire up the default error handling logic If for some reason a DLL is
// missing in the path this will pop up a GUI Dialog explaining the fault so
// the user can either fix their PATH, or report a bug. Without this
// setting, the process exits immediately with a generic exit status but no
// way to (easily) figure out what the actual missing DLL was.
CreationFlags: CREATE_DEFAULT_ERROR_MODE,
}
1 change: 1 addition & 0 deletions llm/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ func NewLlamaServer(gpus gpu.GpuInfoList, model string, ggml *GGML, adapters, pr
s.cmd.Env = os.Environ()
s.cmd.Stdout = os.Stdout
s.cmd.Stderr = s.status
s.cmd.SysProcAttr = LlamaServerSysProcAttr

envWorkarounds := [][2]string{}
for _, gpu := range gpus {
Expand Down

0 comments on commit e12fff8

Please sign in to comment.