${BUILD_NUM_JOBS} not defined in TF lite building script leads to crash
Possible fix: In line 126 of file: `tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh`, replace:
```
cmake --build . --verbose -j ${BUILD_NUM_JOBS} -t _pywrap_tensorflow_interpreter_wrapper
```
with:
```
cmake --build . --verbose -j $(nproc) -t _pywrap_tensorflow_interpreter_wrapper
``` Pull request:
https://github.com/tensorflow/tensorflow/pull/63038 Posted 3 PR for head, r2.15 and r2.16 You can also define the envvar before building:

```bash
BUILD_NUM_JOBS=4 PYTHON=python3 tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh native
```

In fact, this is the way the scripts have been designed to be run a long time ago. One setup script defines the variables and then calls the exported scripts. This is all fine and well. Yet, it's completely undocumented. People will find  the following in the README.md page for tensorflow/lite:
```
PYTHON=python3 tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh native
```
and in more cases than not, their system will crash as the compiler sees a `-j` option with no actual value. At the very least, the documentation should indicate a value is needed. Same for the following pages:
https://www.tensorflow.org/lite/guide/build_cmake_pip
https://www.tensorflow.org/lite/guide/build_cmake Yes, that's why I recommended in #63039 to define a default smallish (~2 / 4?) value in case users are not passing one, instead of pinning to `nproc`. I'd be happy to push a PR with the added definition. On Feb 25, 2024 10:11 AM, Mihai Maruseac ***@***.***> wrote:
Yes, that's why I recommended in #63039 to define a default smallish (~2 / 4?) value in case users are not passing one, instead of pinning to nproc.

—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you authored the thread.Message ID: ***@***.***> Please CC me on the PR and I'll try to speed it up through the internal systems.

Thank you Done. Thank you, @mihaimaruseac This [PR](https://github.com/tensorflow/tensorflow/pull/63049) addressing the issue is now merged. Thanks very much, @mihaimaruseac. Closing. Are you satisfied with the resolution of your issue?
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=Yes&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/63018">Yes</a>
<a href="https://docs.google.com/forms/d/e/1FAIpQLSfaP12TRhd9xSxjXZjcZFNXPGk4kc1-qMdv3gc6bEP90vY1ew/viewform?entry.85265664=No&entry.2137816233=https://github.com/tensorflow/tensorflow/issues/63018">No</a>
 Thank you for the PRs
### Issue type

Build/Install

### Have you reproduced the bug with TensorFlow Nightly?

Yes

### Source

source

### TensorFlow version

2.15.0

### Custom code

No

### OS platform and distribution

Ubuntu 22.04

### Mobile device

_No response_

### Python version

3.10

### Bazel version

_No response_

### GCC/compiler version

_No response_

### CUDA/cuDNN version

_No response_

### GPU model and memory

_No response_

### Current behavior?

in line 126 of file: `tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh`
```
cmake --build . --verbose -j ${BUILD_NUM_JOBS} -t _pywrap_tensorflow_interpreter_wrapper
```
the variable `${BUILD_NUM_JOBS}` is never defined. When compilation fo TF lite is carried out with cmake (docker, native) there is no limit in the number of processes used for compilation. This leads to a massive RAM/swap usage and in some cases when these resources run out, a crash (with logged error: `Killed signal terminated program cc1plus`).

The `${BUILD_NUM_JOBS}` variable should be set earlier in the script or replaced with a `-j 4`.





### Standalone code to reproduce the issue

```shell
PYTHON=python3 tensorflow/lite/tools/pip_package/build_pip_package_with_cmake.sh native
```


### Relevant log output

_No response_