Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 52 additions & 22 deletions docs/source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,76 @@
Local Installation
==================

Step 1: Get Miniconda
^^^^^^^^^^^^^^^^^^^^^
Step 1: Install Python
^^^^^^^^^^^^^^^^^^^^^^

This is a Python package, and it depends on other packages to work. To manage
all this, it's recommended to use Miniconda. Get it from
https://docs.anaconda.com/miniconda/
Install Python 3.9 or newer.

Step 2: Install NAM
^^^^^^^^^^^^^^^^^^^
Step 2: Create a virtual environment
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It's recommended to install NAM in a virtual environment.

On macOS / Linux:

.. code-block:: console

$ python -m venv .venv
$ source .venv/bin/activate
$ python -m pip install --upgrade pip

On Windows, in ``cmd.exe``:

.. code-block:: console

Now that we have Miniconda, we can install NAM using it.
> python -m venv .venv
> .venv\Scripts\activate
> python -m pip install --upgrade pip

Comment thread
HundredBillion marked this conversation as resolved.
(Windows / Linux users) If your computer has an nVIDIA GPU, you should install a
GPU-compatible version of PyTorch first.
`The PyTorch website <https://pytorch.org/get-started/locally/>`_ will always
have the most up-to-date guidance for this. Currently, this is the command:
On Windows, in PowerShell:

.. code-block:: console

$ pip install torch --index-url https://download.pytorch.org/whl/cu129
> python -m venv .venv
> .\.venv\Scripts\Activate.ps1
> python -m pip install --upgrade pip

Step 3: Install PyTorch
^^^^^^^^^^^^^^^^^^^^^^^

If your computer has an NVIDIA GPU, install a GPU-compatible version of
PyTorch using the instructions on the PyTorch website:

Then, install NAM using pip:
https://pytorch.org/get-started/locally/

Step 4: Install NAM
^^^^^^^^^^^^^^^^^^^

.. code-block:: console

$ pip install neural-amp-modeler
$ python -m pip install neural-amp-modeler

To update an existing installation:

.. code-block:: console

pip install --upgrade neural-amp-modeler
$ python -m pip install --upgrade neural-amp-modeler

Local development installation
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

If you're interested in developing this package, there are Anaconda environment
definitions included in the ``environments/`` directory. Use the one that's
appropriate for the platform you're developing on. The
``.github/workflows/python-pckage.yml`` is also helpful if you want to be sure
Create and activate a virtual environment, then install NAM in editable mode
with its test dependencies. On Windows, use the activation command above for
your shell. Install any additional development tooling you need alongside it:

.. code-block:: console

$ python -m venv .venv
$ source .venv/bin/activate
$ python -m pip install --upgrade pip
$ python -m pip install -e ".[dev,test]"

``.github/workflows/python-package.yml`` is also helpful if you want to be sure
that you're testing your developments in the same way that contributions will be
automatically tested (via GitHub Actions).

Expand All @@ -51,7 +81,7 @@ Trouble using the GPU?
^^^^^^^^^^^^^^^^^^^^^^

If you're using a Windows or Linux machine with an NVIDIA GPU and NAM isn't
using it (Apple machines with Apple Silicon don't use an nVIDIA GPU, but MPS, an
using it (Apple machines with Apple Silicon don't use an NVIDIA GPU, but MPS, an
accelerator with somewhat similar functionality), the reason is 99.999% probably
an issue with your PyTorch installation, not NAM. Google (or ChatGPT) should be
able to help you fix the issue, but here are a few handy things you can do (in
Expand Down Expand Up @@ -81,7 +111,7 @@ To uninstall PyTorch and reinstall it, you can do:

.. code-block:: console

$ pip uninstall torch torchvision torchaudio
$ python -m pip uninstall torch torchvision torchaudio

and then use the install command above (or check the PyTorch website for the
most up-to-date instructions). If you notice that this documentation is out of
Expand Down
38 changes: 0 additions & 38 deletions environments/environment_cpu_apple.yml

This file was deleted.

39 changes: 0 additions & 39 deletions environments/environment_gpu.yml

This file was deleted.

6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ transformers-compat = [
"numpy", # NB: Older PyTorch versions require numpy<2
]

dev = [
"black",
"flake8",
"pre-commit",
]

test = [
"pytest",
"pytest-mock",
Expand Down
55 changes: 13 additions & 42 deletions tests/test_graceful_shutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ def run_training_with_interrupt(
interrupt_after_training_starts: bool = True,
interrupt_delay: float = 2.0,
timeout: float = 120.0,
conda_env: Optional[str] = None,
) -> Tuple[int, bool, list]:
"""
Run nam-full training and send SIGINT after training starts.
Expand All @@ -248,36 +247,17 @@ def run_training_with_interrupt(
:param interrupt_delay: Seconds to wait after training starts (or after
process start if interrupt_after_training_starts is False)
:param timeout: Maximum time to wait for process to complete
:param conda_env: Name of conda environment to use
:return: (exit_code, graceful_shutdown_detected, nam_files_found)
"""
# Build command
if conda_env:
# Use conda run to execute in the environment
cmd = [
"conda",
"run",
"-n",
conda_env,
"--no-capture-output",
"nam-full",
str(data_config_path),
str(model_config_path),
str(learning_config_path),
str(output_path),
"--no-show",
"--no-plots",
]
else:
cmd = [
"nam-full",
str(data_config_path),
str(model_config_path),
str(learning_config_path),
str(output_path),
"--no-show",
"--no-plots",
]
cmd = [
"nam-full",
str(data_config_path),
str(model_config_path),
str(learning_config_path),
str(output_path),
"--no-show",
"--no-plots",
]

print(f"Starting training with command: {' '.join(cmd)}")

Expand Down Expand Up @@ -387,7 +367,7 @@ def run_training_with_interrupt(
return exit_code, graceful_shutdown_detected, nam_files


def test_graceful_shutdown(conda_env: Optional[str] = None) -> bool:
def test_graceful_shutdown() -> bool:
"""
Test that graceful shutdown generates a model file.

Expand Down Expand Up @@ -422,7 +402,6 @@ def test_graceful_shutdown(conda_env: Optional[str] = None) -> bool:
interrupt_after_training_starts=True,
interrupt_delay=2.0, # Wait 2s after training starts
timeout=120.0,
conda_env=conda_env,
)

print("\n" + "=" * 60)
Expand Down Expand Up @@ -491,7 +470,6 @@ def test_graceful_shutdown_generates_model(self):
interrupt_after_training_starts=True,
interrupt_delay=2.0, # Wait 2s after training starts
timeout=120.0,
conda_env=None, # Use current environment in pytest
)

# Assert that a .nam file was created
Expand All @@ -506,18 +484,11 @@ def main():
"""Run the graceful shutdown test."""
import argparse

parser = argparse.ArgumentParser(
argparse.ArgumentParser(
description="Test graceful shutdown model generation"
)
parser.add_argument(
"--conda-env",
type=str,
default=None,
help="Conda environment to use for running nam-full",
)
args = parser.parse_args()
).parse_args()

success = test_graceful_shutdown(conda_env=args.conda_env)
success = test_graceful_shutdown()
sys.exit(0 if success else 1)


Expand Down