Skip to content

Commit 4792935

Browse files
bwastirtourgeman
authored andcommitted
Cache the environment variable check for batch invariance (vllm-project#26510)
Signed-off-by: Bram Wasti <bwasti@meta.com>
1 parent 614934f commit 4792935

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

csrc/core/batch_invariant.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ namespace vllm {
88
// vllm_kernel_override_batch_invariant(); returns true
99
// if env VLLM_KERNEL_OVERRIDE_BATCH_INVARIANT=1
1010
inline bool vllm_kernel_override_batch_invariant() {
11-
std::string env_key = "VLLM_KERNEL_OVERRIDE_BATCH_INVARIANT";
12-
const char* val = std::getenv(env_key.c_str());
13-
return (val && std::atoi(val) != 0) ? 1 : 0;
11+
static bool cached = []() {
12+
std::string env_key = "VLLM_KERNEL_OVERRIDE_BATCH_INVARIANT";
13+
const char* val = std::getenv(env_key.c_str());
14+
return (val && std::atoi(val) != 0) ? 1 : 0;
15+
}();
16+
return cached;
1417
}
1518

1619
} // namespace vllm

0 commit comments

Comments
 (0)