Skip to content

Commit

Permalink
Add GitHub action to format and lint code (#361)
Browse files Browse the repository at this point in the history
* Add and run pre-commit hooks

* Fix spacing

* Normalize spacing
  • Loading branch information
dyastremsky authored Jul 5, 2023
1 parent ae8103c commit 66543e5
Show file tree
Hide file tree
Showing 41 changed files with 3,470 additions and 1,338 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]

74 changes: 74 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Copyright 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of NVIDIA CORPORATION nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

repos:
- repo: https://github.com/timothycrosley/isort
rev: 5.12.0
hooks:
- id: isort
additional_dependencies: [toml]
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
types_or: [python, cython]
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
args: [--max-line-length=88, --select=C,E,F,W,B,B950, --extend-ignore = E203,E501]
types_or: [python, cython]
- repo: https://github.com/pre-commit/mirrors-clang-format
rev: v16.0.5
hooks:
- id: clang-format
types_or: [c, c++, cuda, proto, textproto, java]
args: ["-fallback-style=none", "-style=file", "-i"]
- repo: https://github.com/codespell-project/codespell
rev: v2.2.4
hooks:
- id: codespell
additional_dependencies: [tomli]
args: ["--toml", "pyproject.toml"]
exclude: (?x)^(.*stemmer.*|.*stop_words.*|^CHANGELOG.md$)
# More details about these pre-commit hooks here:
# https://pre-commit.com/hooks.html
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-case-conflict
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: check-json
- id: check-toml
- id: check-yaml
- id: check-shebang-scripts-are-executable
- id: end-of-file-fixer
types_or: [c, c++, cuda, proto, textproto, java, python]
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace

12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ else()

##############################################################################
# - install targets-----------------------------------------------------------

add_library(
${BACKEND_TARGET} SHARED
src/api.cc
Expand Down Expand Up @@ -208,12 +208,12 @@ else()
INTERFACE_POSITION_INDEPENDENT_CODE ON
)
endif()

target_compile_options(${BACKEND_TARGET}
PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${RAPIDS_TRITON_BACKEND_CXX_FLAGS}>"
"$<$<COMPILE_LANGUAGE:CUDA>:${RAPIDS_TRITON_BACKEND_CUDA_FLAGS}>"
)

target_include_directories(${BACKEND_TARGET}
PRIVATE "$<BUILD_INTERFACE:${RAPIDS_TRITON_BACKEND_SOURCE_DIR}/include>"
"${CMAKE_CURRENT_SOURCE_DIR}/src"
Expand Down Expand Up @@ -246,15 +246,15 @@ else()
if(NOT TRITON_FIL_USE_TREELITE_STATIC)
list(APPEND BACKEND_TARGET ${TREELITE_LIBS_NO_PREFIX})
endif()

install(
TARGETS ${BACKEND_TARGET}
LIBRARY DESTINATION ${BACKEND_FOLDER}/${BACKEND_NAME}
)

##############################################################################
# - build test executable ----------------------------------------------------

# TODO (wphicks)
# if(BUILD_TESTS)
# include(test/CMakeLists.txt)
Expand Down
14 changes: 7 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,25 @@ To contribute code to this project, please follow these steps:
```
Developer Certificate of Origin
Version 1.1
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129
Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed.
```
```
Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
(a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or
(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or
(c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.
```

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
identification within third-party archives.

Copyright 2021 NVIDIA CORPORATION

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ model_repository/
backend: "fil"
max_batch_size: 32768
input [
{
{
name: "input__0"
data_type: TYPE_FP32
dims: [ $NUM_FEATURES ]
}
dims: [ $NUM_FEATURES ]
}
]
output [
{
Expand Down
6 changes: 3 additions & 3 deletions docs/explainability.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ output [
backend: "fil"
max_batch_size: 32768
input [
{
{
name: "input__0"
data_type: TYPE_FP32
dims: [ $NUM_FEATURES ]
}
dims: [ $NUM_FEATURES ]
}
]
output [
{
Expand Down
14 changes: 7 additions & 7 deletions docs/model_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ A typical `config.pbtxt` file might look something like this:
```protobuf
backend: "fil"
max_batch_size: 32768
input [
{
input [
{
name: "input__0"
data_type: TYPE_FP32
dims: [ 32 ]
}
dims: [ 32 ]
}
]
output [
{
Expand Down Expand Up @@ -129,11 +129,11 @@ Below, we see an example I/O specification for a model with 32 input
features and 3 output classes with the `predict_proba` flag enabled:
```
input [
{
{
name: "input__0"
data_type: TYPE_FP32
dims: [ 32 ]
}
dims: [ 32 ]
}
]
output [
{
Expand Down
4 changes: 2 additions & 2 deletions notebooks/simple-xgboost/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This notebook is a reference for deploying an XGBoost model on Triton with the F
* [Docker](https://docs.docker.com/get-docker/)
* [The NVIDIA container toolkit](https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker)

## Run the Triton Inference Server container
## Run the Triton Inference Server container

**Note:** Due to a bug in release 21.07, Triton's `model_analyzer` cannot be used with the FIL backend. If you wish to use the model analyzer, please use release 21.08 or later.

Expand All @@ -28,7 +28,7 @@ docker run \
--rm \
--net=host \
--name triton_fil \
nvcr.io/nvidia/tritonserver:<tag> # Put the appropriate tag here.
nvcr.io/nvidia/tritonserver:<tag> # Put the appropriate tag here.
```

**Note:** The artifacts created by scripts inside the container are created with root permission. The user on host machine might not be able to modify the artifacts once the container exists. To avoid this issue, copy the notebook `docker cp simple_xgboost_example.ipynb <docker_ID>` and create the artifacts inside the container.
Expand Down
Empty file modified ops/gpuci_conda_retry
100644 → 100755
Empty file.
39 changes: 19 additions & 20 deletions ops/move_deps.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@

import os
import re
import subprocess
import shutil
import subprocess
from pathlib import Path

MISSING_REGEX = re.compile(r'\n\t(.+)\ =>\ not\ found')
FOUND_REGEX = re.compile(r'\n\t(.+)\ =>\ (.+)\ (\(0[xX][0-9a-fA-F]+\))')
MISSING_REGEX = re.compile(r"\n\t(.+)\ =>\ not\ found")
FOUND_REGEX = re.compile(r"\n\t(.+)\ =>\ (.+)\ (\(0[xX][0-9a-fA-F]+\))")


def ldd(path):
"""Get output of ldd for given file"""
ldd_out = subprocess.run(
['ldd', path], check=True, capture_output=True, text=True
)
ldd_out = subprocess.run(["ldd", path], check=True, capture_output=True, text=True)
return ldd_out.stdout


Expand Down Expand Up @@ -52,34 +50,34 @@ def move_dependencies():
location and repeats the analysis until it has satisfied as many missing
dependencies as possible.
"""
fil_lib = os.getenv('FIL_LIB', 'libtriton_fil.so')
lib_dir = os.getenv('LIB_DIR', '/usr/lib')
fil_lib = os.getenv("FIL_LIB", "libtriton_fil.so")
lib_dir = os.getenv("LIB_DIR", "/usr/lib")

conda_lib_dir = os.getenv('CONDA_LIB_DIR')
conda_lib_dir = os.getenv("CONDA_LIB_DIR")
if conda_lib_dir is None:
conda_prefix = os.getenv('CONDA_PREFIX')
conda_prefix = os.getenv("CONDA_PREFIX")
if conda_prefix is None:
raise RuntimeError(
'Must set CONDA_LIB_DIR to conda environment lib directory'
"Must set CONDA_LIB_DIR to conda environment lib directory"
)
conda_lib_dir = os.path.join(conda_prefix, 'lib')
conda_lib_dir = os.path.join(conda_prefix, "lib")

Path(lib_dir).mkdir(parents=True, exist_ok=True)

# Set RUNPATH to conda lib directory to determine locations of
# conda-provided dependencies
subprocess.run(
['patchelf', '--set-rpath', conda_lib_dir, fil_lib], check=True
)
subprocess.run(["patchelf", "--set-rpath", conda_lib_dir, fil_lib], check=True)

ldd_out = ldd(fil_lib)
expected_missing = set(get_missing_deps(ldd_out))
deps_map = get_deps_map(ldd_out, required_dir=conda_lib_dir)

# Set RUNPATH to final dependency directory
subprocess.run(['patchelf', '--set-rpath', lib_dir, fil_lib], check=True)
subprocess.run(["patchelf", "--set-rpath", lib_dir, fil_lib], check=True)

prev_missing = {None, }
prev_missing = {
None,
}
cur_missing = set()
while prev_missing != cur_missing:
prev_missing = cur_missing
Expand All @@ -93,11 +91,12 @@ def move_dependencies():

remaining = cur_missing - expected_missing
if remaining != {}:
print('Could not find the following dependencies:')
print("Could not find the following dependencies:")
for lib in sorted(remaining):
print(lib)
else:
print('All dependencies found')
print("All dependencies found")


if __name__ == '__main__':
if __name__ == "__main__":
move_dependencies()
Loading

0 comments on commit 66543e5

Please sign in to comment.