Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/branch-24.10' into complete-re…
Browse files Browse the repository at this point in the history
…move-multi-message
  • Loading branch information
yczhang-nv committed Sep 6, 2024
2 parents f4be468 + 3a28c5b commit c4a7095
Show file tree
Hide file tree
Showing 51 changed files with 229 additions and 207 deletions.
20 changes: 20 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@ repos:
hooks:
- id: rapids-dependency-file-generator
args: ["--clean"]
- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort
args: ["--settings-file=./pyproject.toml"]
files: ^python/
- repo: https://github.com/PyCQA/flake8
rev: 6.1.0
hooks:
- id: flake8
entry: pflake8
additional_dependencies: [pyproject-flake8]
args: ["--config=./pyproject.toml"]
files: ^python/
- repo: https://github.com/google/yapf
rev: v0.40.2
hooks:
- id: yapf
args: ["--style", "./pyproject.toml"]
files: ^python/

default_language_version:
python: python3
2 changes: 1 addition & 1 deletion ci/scripts/fix_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ fi
# Run yapf
if [[ "${SKIP_YAPF}" == "" ]]; then
echo "Running yapf..."
python3 -m yapf -i --style ${PY_CFG} -r ${PY_MODIFIED_FILES[@]}
python3 -m yapf -i --style ${PROJ_TOML} -r ${PY_MODIFIED_FILES[@]}
fi
60 changes: 1 addition & 59 deletions ci/scripts/python_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ LC_ALL=C.UTF-8
LANG=C.UTF-8

# Pre-populate the return values in case they are skipped
ISORT_RETVAL=0
FLAKE_RETVAL=0
PYLINT_RETVAL=0
YAPF_RETVAL=0

get_modified_files ${PYTHON_FILE_REGEX} MORPHEUS_MODIFIED_FILES

Expand All @@ -41,45 +38,16 @@ if [[ -n "${MORPHEUS_MODIFIED_FILES}" ]]; then
echo " $f"
done

if [[ "${SKIP_ISORT}" == "" ]]; then
ISORT_OUTPUT=`python3 -m isort --settings-file ${PROJ_TOML} --filter-files --check-only ${MORPHEUS_MODIFIED_FILES[@]} 2>&1`
ISORT_RETVAL=$?
fi

if [[ "${SKIP_PYLINT}" == "" ]]; then
NUM_PROC=$(get_num_proc)
PYLINT_OUTPUT=`pylint -j ${NUM_PROC} ${MORPHEUS_MODIFIED_FILES[@]} 2>&1`
PYLINT_RETVAL=$?
fi

if [[ "${SKIP_FLAKE}" == "" ]]; then
FLAKE_OUTPUT=`python3 -m flake8 --config ${PY_CFG} ${MORPHEUS_MODIFIED_FILES[@]} 2>&1`
FLAKE_RETVAL=$?
fi

if [[ "${SKIP_YAPF}" == "" ]]; then
# Run yapf. Will return 1 if there are any diffs
YAPF_OUTPUT=`python3 -m yapf --style ${PY_CFG} --diff ${MORPHEUS_MODIFIED_FILES[@]} 2>&1`
YAPF_RETVAL=$?
fi

else
echo "No modified Python files to check"
fi

# Output results if failure otherwise show pass
if [[ "${SKIP_ISORT}" != "" ]]; then
echo -e "\n\n>>>> SKIPPED: isort check\n\n"
elif [ "${ISORT_RETVAL}" != "0" ]; then
echo -e "\n\n>>>> FAILED: isort style check; begin output\n\n"
echo -e "${ISORT_OUTPUT}"
echo -e "\n\n>>>> FAILED: isort style check; end output\n\n" \
"To auto-fix many issues (not all) run:\n" \
" ./ci/scripts/fix_all.sh\n\n"
else
echo -e "\n\n>>>> PASSED: isort style check\n\n"
fi

if [[ "${SKIP_PYLINT}" != "" ]]; then
echo -e "\n\n>>>> SKIPPED: pylint check\n\n"
elif [ "${PYLINT_RETVAL}" != "0" ]; then
Expand All @@ -90,33 +58,7 @@ else
echo -e "\n\n>>>> PASSED: pylint style check\n\n"
fi

if [[ "${SKIP_FLAKE}" != "" ]]; then
echo -e "\n\n>>>> SKIPPED: flake8 check\n\n"
elif [ "${FLAKE_RETVAL}" != "0" ]; then
echo -e "\n\n>>>> FAILED: flake8 style check; begin output\n\n"
echo -e "${FLAKE_OUTPUT}"
echo -e "\n\n>>>> FAILED: flake8 style check; end output\n\n" \
"To auto-fix many issues (not all) run:\n" \
" ./ci/scripts/fix_all.sh\n\n"
else
echo -e "\n\n>>>> PASSED: flake8 style check\n\n"
fi

if [[ "${SKIP_YAPF}" != "" ]]; then
echo -e "\n\n>>>> SKIPPED: yapf check\n\n"
elif [ "${YAPF_RETVAL}" != "0" ]; then
echo -e "\n\n>>>> FAILED: yapf style check; begin output\n\n"
echo -e "Incorrectly formatted files:"
YAPF_OUTPUT=`echo "${YAPF_OUTPUT}" | sed -nr 's/^\+\+\+ ([^ ]*) *\(reformatted\)$/\1/p'`
echo -e "${YAPF_OUTPUT}"
echo -e "\n\n>>>> FAILED: yapf style check; end output\n\n" \
"To auto-fix many issues (not all) run:\n" \
" ./ci/scripts/fix_all.sh\n\n"
else
echo -e "\n\n>>>> PASSED: yapf style check\n\n"
fi

RETVALS=(${ISORT_RETVAL} ${FLAKE_RETVAL} ${PYLINT_RETVAL} ${YAPF_RETVAL})
RETVALS=(${PYLINT_RETVAL})
IFS=$'\n'
RETVAL=`echo "${RETVALS[*]}" | sort -nr | head -n1`

Expand Down
4 changes: 2 additions & 2 deletions docs/source/developer_guide/guides/2_real_world_phishing.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ To start, we will need to instantiate and set a few attributes of the `Config` c
config = Config()
config.mode = PipelineModes.NLP

config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))
config.feature_length = model_fea_length

with open(labels_file, encoding='UTF-8') as fh:
Expand Down Expand Up @@ -563,7 +563,7 @@ def run_pipeline(use_stage_function: bool,
config.mode = PipelineModes.NLP

# Set the thread count to match our cpu count
config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))
config.feature_length = model_fea_length

with open(labels_file, encoding='UTF-8') as fh:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ from morpheus.cli.utils import load_labels_file
CppConfig.set_should_use_cpp(False)

config = Config()
config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))
config.ae = ConfigAutoEncoder()
config.ae.feature_columns = load_labels_file(get_package_relative_file("data/columns_ae_azure.txt"))
```
Expand Down
2 changes: 1 addition & 1 deletion examples/abp_pcap_detection/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@click.command()
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
help="Number of internal pipeline threads to use.",
)
Expand Down
2 changes: 1 addition & 1 deletion examples/developer_guide/2_1_real_world_phishing/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def run_pipeline(use_stage_function: bool,
config.mode = PipelineModes.NLP

# Set the thread count to match our cpu count
config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))
config.feature_length = model_fea_length

with open(labels_file, encoding='UTF-8') as fh:
Expand Down
2 changes: 1 addition & 1 deletion examples/developer_guide/2_2_rabbitmq/read_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def run_pipeline(use_source_function: bool):
configure_logging(log_level=logging.DEBUG)

config = Config()
config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))

# Create a linear pipeline object
pipeline = LinearPipeline(config)
Expand Down
2 changes: 1 addition & 1 deletion examples/developer_guide/2_2_rabbitmq/write_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run_pipeline():
input_file = os.path.join(root_dir, 'examples/data/email.jsonlines')

config = Config()
config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))

# Create a linear pipeline object
pipeline = LinearPipeline(config)
Expand Down
2 changes: 1 addition & 1 deletion examples/developer_guide/4_rabbitmq_cpp_stage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ limitations under the License.
# Example RabbitMQ stages
This example builds upon the `examples/developer_guide/2_2_rabbitmq` example adding a C++ implementation for the `RabbitMQSourceStage` along with adding package install scripts.

This example adds two flags to the `read_simple.py` script. A `--use_cpp` flag which defaults to `True` and a `--num_threads` flag which defaults to the number of cores on the system as returned by `os.cpu_count()`.
This example adds two flags to the `read_simple.py` script. A `--use_cpp` flag which defaults to `True` and a `--num_threads` flag which defaults to the number of cores on the system as returned by `len(os.sched_getaffinity(0))`.

## Supported Environments
| Environment | Supported | Notes |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@click.option('--use_cpp', default=True)
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
help="Number of internal pipeline threads to use",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def run_pipeline():
input_file = os.path.join(root_dir, 'examples/data/email.jsonlines')

config = Config()
config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))

# Create a linear pipeline object
pipeline = LinearPipeline(config)
Expand Down
2 changes: 1 addition & 1 deletion examples/digital_fingerprinting/production/grafana/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def run_pipeline(train_users,

CppConfig.set_should_use_cpp(False)

config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))

config.ae = ConfigAutoEncoder()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def generate_ae_config(source: str,
pipeline_batch_size: int = 0,
edge_buffer_size: int = 0,
use_cpp: bool = False,
num_threads: int = os.cpu_count()):
num_threads: int = len(os.sched_getaffinity(0))):
config = Config()

CppConfig.set_should_use_cpp(use_cpp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def run_pipeline(train_users,

CppConfig.set_should_use_cpp(False)

config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))

config.ae = ConfigAutoEncoder()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def run_pipeline(train_users,

CppConfig.set_should_use_cpp(False)

config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))

config.ae = ConfigAutoEncoder()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
"\n",
"CppConfig.set_should_use_cpp(False)\n",
"\n",
"config.num_threads = os.cpu_count()\n",
"config.num_threads = len(os.sched_getaffinity(0))\n",
"\n",
"config.ae = ConfigAutoEncoder()\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
"\n",
"CppConfig.set_should_use_cpp(False)\n",
"\n",
"config.num_threads = os.cpu_count()\n",
"config.num_threads = len(os.sched_getaffinity(0))\n",
"\n",
"config.ae = ConfigAutoEncoder()\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
"\n",
"CppConfig.set_should_use_cpp(False)\n",
"\n",
"config.num_threads = os.cpu_count()\n",
"config.num_threads = len(os.sched_getaffinity(0))\n",
"\n",
"config.ae = ConfigAutoEncoder()\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
"\n",
"CppConfig.set_should_use_cpp(False)\n",
"\n",
"config.num_threads = os.cpu_count()\n",
"config.num_threads = len(os.sched_getaffinity(0))\n",
"\n",
"config.ae = ConfigAutoEncoder()\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@click.command()
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
help="Number of internal pipeline threads to use",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def run_pipeline(train_users,

CppConfig.set_should_use_cpp(False)

config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))

config.ae = ConfigAutoEncoder()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def run_pipeline(train_users,

CppConfig.set_should_use_cpp(False)

config.num_threads = os.cpu_count()
config.num_threads = len(os.sched_getaffinity(0))

config.ae = ConfigAutoEncoder()

Expand Down
2 changes: 1 addition & 1 deletion examples/doca/run_udp_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
)
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
show_default=True,
help="Number of internal pipeline threads to use.",
Expand Down
2 changes: 1 addition & 1 deletion examples/gnn_fraud_detection_pipeline/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@click.command()
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
help="Number of internal pipeline threads to use.",
)
Expand Down
4 changes: 2 additions & 2 deletions examples/llm/agents/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run():
@run.command(help="Runs a simple finite pipeline with a single execution of a LangChain agent from a fixed input")
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
help="Number of internal pipeline threads to use",
)
Expand Down Expand Up @@ -67,7 +67,7 @@ def simple(**kwargs):
@run.command(help="Runs a pipeline LangChain agents which pulls inputs from a Kafka message bus")
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
help="Number of internal pipeline threads to use",
)
Expand Down
2 changes: 1 addition & 1 deletion examples/llm/completion/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def run():
@run.command()
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
help="Number of internal pipeline threads to use",
)
Expand Down
2 changes: 1 addition & 1 deletion examples/llm/rag/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def run():
@run.command()
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
help="Number of internal pipeline threads to use",
)
Expand Down
2 changes: 1 addition & 1 deletion examples/llm/vdb_upload/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def run():
)
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
help="Number of internal pipeline threads to use",
)
Expand Down
2 changes: 1 addition & 1 deletion examples/log_parsing/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
@click.command()
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
help="Number of internal pipeline threads to use.",
)
Expand Down
2 changes: 1 addition & 1 deletion examples/ransomware_detection/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
@click.option('--use_cpp', default=False, help="Enable C++ execution for this pipeline, currently this is unsupported.")
@click.option(
"--num_threads",
default=os.cpu_count(),
default=len(os.sched_getaffinity(0)),
type=click.IntRange(min=1),
help="Number of internal pipeline threads to use.",
)
Expand Down
Loading

0 comments on commit c4a7095

Please sign in to comment.