9
9
10
10
namespace LLMUnity
11
11
{
12
+ [ DefaultExecutionOrder ( - 2 ) ]
12
13
public class LLM : LLMClient
13
14
{
14
15
[ HideInInspector ] public bool modelHide = true ;
15
16
16
17
[ Server ] public int numThreads = - 1 ;
17
18
[ Server ] public int numGPULayers = 0 ;
19
+ [ ServerAdvanced ] public int parallelPrompts = - 1 ;
18
20
[ ServerAdvanced ] public bool debug = false ;
19
21
20
22
[ Model ] public string model = "" ;
@@ -36,7 +38,7 @@ public class LLM : LLMClient
36
38
private static float binariesDone = 0 ;
37
39
private Process process ;
38
40
private bool serverListening = false ;
39
- private static ManualResetEvent serverStarted = new ManualResetEvent ( false ) ;
41
+ public ManualResetEvent serverStarted = new ManualResetEvent ( false ) ;
40
42
41
43
private static string GetAssetPath ( string relPath = "" ) {
42
44
// Path to store llm server binaries and models
@@ -95,7 +97,7 @@ public async void SetLora(string path){
95
97
}
96
98
#endif
97
99
98
- new void OnEnable ( )
100
+ new public void OnEnable ( )
99
101
{
100
102
// start the llm server and run the OnEnable of the client
101
103
StartLLMServer ( ) ;
@@ -156,16 +158,17 @@ private void StartLLMServer()
156
158
if ( ! File . Exists ( loraPath ) ) throw new System . Exception ( $ "File { loraPath } not found!") ;
157
159
}
158
160
161
+ int slots = parallelPrompts == - 1 ? FindObjectsOfType < LLMClient > ( ) . Length : parallelPrompts ;
159
162
string binary = server ;
160
- string arguments = $ " --port { port } -m { modelPath } -c { contextSize } -b { batchSize } --log-disable --nobrowser";
163
+ string arguments = $ " --port { port } -m \" { modelPath } \" -c { contextSize } -b { batchSize } --log-disable --nobrowser -np { slots } ";
161
164
if ( numThreads > 0 ) arguments += $ " -t { numThreads } ";
162
165
if ( numGPULayers > 0 ) arguments += $ " -ngl { numGPULayers } ";
163
- if ( loraPath != "" ) arguments += $ " --lora { loraPath } ";
166
+ if ( loraPath != "" ) arguments += $ " --lora \" { loraPath } \" ";
164
167
List < ( string , string ) > environment = null ;
165
168
166
169
if ( Application . platform != RuntimePlatform . WindowsEditor && Application . platform != RuntimePlatform . WindowsPlayer ) {
167
170
// use APE binary directly if not on Windows
168
- arguments = $ "{ binary } { arguments } ";
171
+ arguments = $ "\" { binary } \" { arguments } ";
169
172
binary = SelectApeBinary ( ) ;
170
173
if ( numGPULayers <= 0 ) {
171
174
// prevent nvcc building if not using GPU
@@ -175,7 +178,7 @@ private void StartLLMServer()
175
178
Debug . Log ( $ "Server command: { binary } { arguments } ") ;
176
179
process = LLMUnitySetup . CreateProcess ( binary , arguments , CheckIfListening , DebugLogError , environment ) ;
177
180
// wait for at most 2'
178
- serverStarted . WaitOne ( 120000 ) ;
181
+ serverStarted . WaitOne ( 60000 ) ;
179
182
}
180
183
181
184
public void StopProcess ( )
0 commit comments