28
28
29
29
#include < filesystem>
30
30
31
- #include " python_be.h"
32
31
#include " pb_utils.h"
32
+ #include " python_be.h"
33
33
34
34
#ifdef _WIN32
35
35
#include < process.h> // getpid()
36
36
#endif
37
37
38
- extern char ** environ;
38
+ extern char ** environ;
39
39
40
40
namespace triton { namespace backend { namespace python {
41
41
@@ -345,13 +345,13 @@ StubLauncher::Launch()
345
345
TRITONSERVER_ERROR_INVALID_ARG,
346
346
" Invalid stub name: contains invalid characters" );
347
347
}
348
-
348
+
349
349
if (!IsValidPath (model_path_)) {
350
350
return TRITONSERVER_ErrorNew (
351
351
TRITONSERVER_ERROR_INVALID_ARG,
352
352
" Invalid model path: contains invalid characters or not absolute" );
353
353
}
354
-
354
+
355
355
if (!IsValidIdentifier (shm_region_name_)) {
356
356
return TRITONSERVER_ErrorNew (
357
357
TRITONSERVER_ERROR_INVALID_ARG,
@@ -372,12 +372,12 @@ StubLauncher::Launch()
372
372
// Validate the stub executable path
373
373
if (!IsValidPath (python_backend_stub)) {
374
374
return TRITONSERVER_ErrorNew (
375
- TRITONSERVER_ERROR_INVALID_ARG,
376
- " Invalid python backend stub path" );
375
+ TRITONSERVER_ERROR_INVALID_ARG, " Invalid python backend stub path" );
377
376
}
378
377
379
378
if (!IsExecutableFile (python_backend_stub)) {
380
- // Give the execute permission for the triton_python_backend_stub to the owner.
379
+ // Give the execute permission for the triton_python_backend_stub to the
380
+ // owner.
381
381
int error = chmod (python_backend_stub.c_str (), S_IXUSR);
382
382
if (error != 0 ) {
383
383
return TRITONSERVER_ErrorNew (
@@ -398,24 +398,24 @@ StubLauncher::Launch()
398
398
// revert the LD_LIBRARY_PATH changes to avoid shared library issues in
399
399
// executables and libraries.
400
400
ipc_control_->uses_env = false ;
401
-
401
+
402
402
if (python_execution_env_ != " " ) {
403
-
404
403
// Validate Python environment paths
405
404
if (!IsValidPath (path_to_activate_) || !IsValidPath (path_to_libpython_)) {
406
405
return TRITONSERVER_ErrorNew (
407
- TRITONSERVER_ERROR_INVALID_ARG,
408
- " Invalid Python environment paths" );
406
+ TRITONSERVER_ERROR_INVALID_ARG, " Invalid Python environment paths" );
409
407
}
410
-
408
+
411
409
ipc_control_->uses_env = true ;
412
-
410
+
413
411
// Parse environment variables from activation script
414
- std::map<std::string, std::string> env_vars = ParseActivationScript (path_to_activate_);
415
-
416
- // Prepare environment with additional library path
417
- auto [env_strings, custom_env] = PrepareEnvironment (env_vars, path_to_libpython_);
418
-
412
+ std::map<std::string, std::string> env_vars =
413
+ ParseActivationScript (path_to_activate_);
414
+
415
+ // Prepare environment with additional library path
416
+ auto [env_strings, custom_env] =
417
+ PrepareEnvironment (env_vars, path_to_libpython_);
418
+
419
419
// Set up arguments for direct execution
420
420
arg_strings.push_back (python_backend_stub);
421
421
arg_strings.push_back (model_path_);
@@ -427,7 +427,7 @@ StubLauncher::Launch()
427
427
arg_strings.push_back (std::to_string (ipc_control_handle_));
428
428
arg_strings.push_back (stub_name);
429
429
arg_strings.push_back (runtime_modeldir_);
430
-
430
+
431
431
// Convert strings to char* array for exec
432
432
for (const auto & arg : arg_strings) {
433
433
exec_args.push_back (arg.c_str ());
@@ -437,12 +437,15 @@ StubLauncher::Launch()
437
437
// Log the command being executed
438
438
std::ostringstream log_cmd;
439
439
for (size_t i = 0 ; i < arg_strings.size (); ++i) {
440
- if (i > 0 ) log_cmd << " " ;
440
+ if (i > 0 )
441
+ log_cmd << " " ;
441
442
log_cmd << " '" << arg_strings[i] << " '" ;
442
443
}
443
444
LOG_MESSAGE (
444
445
TRITONSERVER_LOG_VERBOSE,
445
- (std::string (" Starting Python backend stub with custom environment: " ) + log_cmd.str ()).c_str ());
446
+ (std::string (" Starting Python backend stub with custom environment: " ) +
447
+ log_cmd.str ())
448
+ .c_str ());
446
449
447
450
pid_t pid = fork ();
448
451
if (pid < 0 ) {
@@ -451,11 +454,16 @@ StubLauncher::Launch()
451
454
" Failed to fork the stub process for auto-complete." );
452
455
}
453
456
if (pid == 0 ) {
454
- // Replace this child process with the new stub process using custom environment
455
- execve (python_backend_stub.c_str (), const_cast <char **>(exec_args.data ()), custom_env.data ());
457
+ // Replace this child process with the new stub process using custom
458
+ // environment
459
+ execve (
460
+ python_backend_stub.c_str (), const_cast <char **>(exec_args.data ()),
461
+ custom_env.data ());
456
462
// execve() never returns if succeeded. Otherwise, an error has occurred.
457
463
std::stringstream ss;
458
- ss << " Failed to run python backend stub with custom environment. Errno = " << errno << ' \n '
464
+ ss << " Failed to run python backend stub with custom environment. Errno "
465
+ " = "
466
+ << errno << ' \n '
459
467
<< " Python backend stub path: " << python_backend_stub << ' \n '
460
468
<< " Activation script: " << path_to_activate_ << ' \n '
461
469
<< " Library path: " << path_to_libpython_ << ' \n ' ;
@@ -464,7 +472,7 @@ StubLauncher::Launch()
464
472
} else {
465
473
stub_pid_ = pid;
466
474
}
467
-
475
+
468
476
} else {
469
477
arg_strings.push_back (python_backend_stub);
470
478
arg_strings.push_back (model_path_);
@@ -476,7 +484,7 @@ StubLauncher::Launch()
476
484
arg_strings.push_back (std::to_string (ipc_control_handle_));
477
485
arg_strings.push_back (stub_name);
478
486
arg_strings.push_back (runtime_modeldir_);
479
-
487
+
480
488
// Convert strings to char* array for exec
481
489
for (const auto & arg : arg_strings) {
482
490
exec_args.push_back (arg.c_str ());
@@ -486,12 +494,14 @@ StubLauncher::Launch()
486
494
// Log the command being executed
487
495
std::ostringstream log_cmd;
488
496
for (size_t i = 0 ; i < arg_strings.size (); ++i) {
489
- if (i > 0 ) log_cmd << " " ;
497
+ if (i > 0 )
498
+ log_cmd << " " ;
490
499
log_cmd << " '" << arg_strings[i] << " '" ;
491
500
}
492
501
LOG_MESSAGE (
493
502
TRITONSERVER_LOG_VERBOSE,
494
- (std::string (" Starting Python backend stub: " ) + log_cmd.str ()).c_str ());
503
+ (std::string (" Starting Python backend stub: " ) + log_cmd.str ())
504
+ .c_str ());
495
505
496
506
pid_t pid = fork ();
497
507
if (pid < 0 ) {
@@ -974,6 +984,6 @@ StubLauncher::ShareCUDAMemoryPool(
974
984
if (pb_exception.what () != std::string{" " }) {
975
985
throw pb_exception;
976
986
}
977
- }
978
- #endif // TRITON_ENABLE_GPU
987
+ }
988
+ #endif // TRITON_ENABLE_GPU
979
989
}}}; // namespace triton::backend::python
0 commit comments