Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #69

Merged
merged 40 commits into from
Mar 25, 2024
Merged

Dev #69

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fa31eb3
Merge pull request #62 from cair/main
perara Dec 21, 2023
27f72bb
Type hint fixes for vanilla classifier.
perara Dec 27, 2023
2d4a9bd
Added fix for only 1 class.
perara Dec 27, 2023
f82b71e
Boosting performance for s=1.0
olegranmo Dec 29, 2023
6537b94
Added type check for X and Y. They now must be uint32 ndarrays.
perara Dec 27, 2023
4940ac7
Fixes #64. Added xxhash and now hashes the full data structure.
perara Jan 7, 2024
e355b28
* Fix for #63
perara Feb 8, 2024
ed4d1b3
Update
olegranmo Feb 9, 2024
e2de2a0
Update
olegranmo Feb 9, 2024
ab763ed
Fixed bug
olegranmo Feb 10, 2024
2b5403e
32 bit sparse lists
olegranmo Feb 11, 2024
f63d402
32 bit sparse lists
olegranmo Feb 11, 2024
1a62a55
* Added C++ Implementation of TMClassifier - 2x train and test perofm…
perara Mar 4, 2024
203c1f0
Class sum typing tweak
perara Mar 4, 2024
bab8b2b
Updated formatting on tools.py
perara Mar 4, 2024
d3a2838
Updated Tool.c; active_output, indrpt_row and indices_row is now const.
perara Mar 4, 2024
b0ce116
Fixed version of cffi to 1.15
perara Mar 4, 2024
7875c2f
Fixed MNISTDemo.py
perara Mar 4, 2024
2f84821
Added type_i_ii_ratio = type_i_ii_ratio to base.py
perara Mar 4, 2024
74d8a26
Optimized cb_inc and cb_dec. We no longer check on carry == 0
perara Mar 4, 2024
753fc7a
Added math include for clang
perara Mar 4, 2024
d420dbd
* Updated to c++11 compatible span and optional
perara Mar 4, 2024
823ba17
* Added build files for c++ library
perara Mar 5, 2024
83b2650
* Added indent for Tools.c
perara Mar 5, 2024
4041e2c
* Added initial BUILD example for STM32L475VGTX_FLASH.ld
perara Mar 5, 2024
18643a1
Fixed bug
olegranmo Mar 12, 2024
0f73e80
Update
olegranmo Mar 12, 2024
cc75590
* Added TMComposite
perara Mar 15, 2024
5cb0bc9
* Updated installation section in README.md
perara Mar 15, 2024
c42563d
Merge remote-tracking branch 'origin/dev' into dev
perara Mar 15, 2024
701815c
* Updated composite.py
perara Mar 21, 2024
e509736
* Added guide on devcontainers
perara Mar 24, 2024
e8e8424
* Updated examples to a common API.
perara Mar 24, 2024
57d99d4
* Made mp runtime "spawn" to support cuda.
perara Mar 24, 2024
f14b113
* Added metrics function
perara Mar 24, 2024
cb7f674
* Tweaks to allow serialization of results.
perara Mar 24, 2024
b9f8e12
* Removed requirements in examples
perara Mar 25, 2024
e859102
* Updated version check of sklearn
perara Mar 25, 2024
0645987
* Updated TMCoalesced Test
perara Mar 25, 2024
e7c117d
* Update to 0.8.3
perara Mar 25, 2024
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
7 changes: 4 additions & 3 deletions .github/workflows/build-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install -r examples/requirements.txt
- name: Install tmu
run: |
pip install develop .
pip install .
pip install .[composite]
pip install .[examples]
pip install .[tests]
- name: Test with pytest
run: pytest test --doctest-modules --junitxml=junit/test-results-${{ matrix.os }}-${{ matrix.python-version }}.xml
- name: Upload pytest test results
Expand Down
29 changes: 20 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ TMU is a comprehensive repository that encompasses several Tsetlin Machine imple

- Wrappers for C and CUDA-based clause evaluation and updates to enable high-performance computation.

## Guides and Tutorials
- [Setting up efficient Development Environment](docs/tutorials/devcontainers/devcontainers.md)

## 📦 Installation

#### **Prerequisites for Windows**
Expand All @@ -40,7 +43,11 @@ Ubuntu: `sudo apt install libffi-dev`
#### **Installing TMU**
To get started with TMU, run the following command:
```bash
# Installing Stable Branch
pip install git+https://github.com/cair/tmu.git

# Installing Development Branch
pip install git+https://github.com/cair/tmu.git@dev
```

## 🛠 Development
Expand All @@ -49,22 +56,26 @@ If you're looking to contribute or experiment with the codebase, follow these st

1. **Clone the Repository**:
```bash
git clone [email protected]:cair/tmu.git
git clone -b dev [email protected]:cair/tmu.git && cd tmu
```

2. **Set Up Development Environment**:
Navigate to the project directory and compile the C library:
```bash
cd tmu && pip install develop .
# Install TMU
pip install .

# (Alternative): Install TMU in Development Mode
pip install -e .

# Install TMU-Composite
pip install .[composite]

# Install TMU-Composite in Development Mode
pip install -e .[composite]
```

3. **Starting a New Project**:
For your projects, simply create a new folder within 'examples' and initiate your development.

#### Modifying the C Codebase
If you make changes to the C codebase, ensure you recompile the code using:
```bash
pip install develop .
```
For your projects, simply create a new **branch** and then within the 'examples' folder, create a new project and initiate your development.

---
190 changes: 190 additions & 0 deletions docs/tutorials/devcontainers/devcontainers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# Running TMU development in development containers

The recommended way of doing development using TMU is through devcontainers. This is because you get a unified development environment that is independent of your underlying system, making it much more trivial to debug when issues appear, and also is much faster to get up and running.
This guide shows how to run TMU with VSCODE both in remote development with SSH with devcontainers, and finally with Remote SSH combined with Devcontainers

# 0. Prerequisites

- Docker installed on your local machine. **Optional - When not using remote SSH**
- Visual Studio Code installed.
- Remote - Containers extension installed in VSCode.
- Ensure Git is installed on your system. This guide utilizes Git Bash for command execution across all operating systems, including Windows.

# 1. SSH Configuration

### Step 1: Generate SSH Keys

Regardless of your operating system, the first step is to generate an SSH key pair if you haven't done so already or wish to create a new pair for this connection. Open Git Bash and type:

```bash
ssh-keygen -t rsa -b 4096 -C "[email protected]"

```

Replace `[email protected]` with your actual email address for identification purposes. When prompted to "Enter a file in which to save the key," press Enter to accept the default location. You will then be asked to enter a passphrase; you can choose to enter one for added security or press Enter to proceed without a passphrase.

### Step 2: Copy the SSH Key to Your Remote Machine Using `ssh-copy-id`

The `ssh-copy-id` script offers a convenient way to install your public key in a remote machine's `~/.ssh/authorized_keys` file, enabling password-less SSH access. This tool is available on Linux, macOS, and through Git Bash on Windows. Here's how to use it:

### For Linux, macOS, and Windows (Using Git Bash)

1. Open your terminal or Git Bash (for Windows users).
2. Execute the following command, replacing `<username>` with your user on the remote machine and `cair-gpuXX.uia.no` with the remote machine's hostname or IP address:

```bash
ssh-copy-id <username>@cair-gpuXX.uia.no

```

1. You will be prompted to enter the remote machine's password. After successfully authenticating, your SSH key will be added to the remote machine's `~/.ssh/authorized_keys` file.

### Step 3: Verify Your SSH Setup

To test your new SSH key setup, attempt to SSH into your remote machine:

```bash
ssh <username>@cair-gpuXX.uia.no

```

If the setup is correct, you should gain access without being prompted for the remote user's password.

### For Multiple Remote Machines

If you're planning to establish password-less SSH connections with multiple remote machines, simply repeat the above process for each, ensuring your public SSH key is added to each machine's `~/.ssh/authorized_keys` file.

# 2. Development using a Devcontainer

# Step 1: Create the Docker-Compose File

Create a **`docker-compose.yml`** file within your **`.devcontainer`** directory. This file will define your service, including the use of GPUs.

### CUDA Enabled Configuration

**docker-compose.yml** (**`./.devcontainer/docker-compose.yml`**):

```yaml
version: '3.8'
services:
tmu-development:
build:
context: .
dockerfile: Dockerfile
volumes:
- ..:/app
deploy:
resources:
reservations:
devices:
- driver: nvidia
capabilities: [gpu]
count: 1 # Assign number of GPUs or use 'all' to assign all available GPUs
```

### CPU-only Enabled Configuration

**docker-compose.yml** (**`./.devcontainer/docker-compose.yml`**):

```yaml
version: '3.8'
services:
tmu-development:
build:
context: .
dockerfile: Dockerfile
volumes:
- ..:/app

```

## Step 2: Create a Dockerfile

### CUDA Enabled Configuration

**Dockerfile** (**`./.devcontainer/Dockerfile`**):

```docker
FROM nvidia/cuda:12.3.2-cudnn9-devel-ubuntu22.04

# Install Python and other dependencies
RUN apt-get update && apt-get install -y python3-pip

# Install TMU?, other relevant stuff

WORKDIR /app
COPY . /app

# You should have a requirements.txt to define your dependencies
RUN pip3 install --no-cache-dir -r requirements.txt

CMD [ "tail", "-f", "/dev/null" ]
```

### CPU-only Enabled Configuration

**Dockerfile** (**`./.devcontainer/Dockerfile`**):

```docker
FROM ubuntu:22.04

# Install Python and pip
RUN apt-get update && apt-get install -y python3 python3-pip

# Optionally install other dependencies, tools, etc.

WORKDIR /app
COPY . /app

# If you have a requirements.txt, install dependencies
RUN pip3 install --no-cache-dir -r requirements.txt

CMD [ "tail", "-f", "/dev/null" ]

```

## Step 3: Create devcontainer.json for Docker-Compose

Create **`devcontainer.json`**

**devcontainer.json** (**`./.devcontainer/devcontainer.json`**):

```json

{
"name": "TMU Devcontainer",
"dockerComposeFile": "docker-compose.yml",
"service": "tmu-development",
"workspaceFolder": "/app",
"extensions": [
"ms-python.python",
],
"forwardPorts": [],
"postCreateCommand": "echo 'Devcontainer is ready'",
"remoteUser": "root"
}
```

## **Using the Setup**

- After configuring your **`.devcontainer`** directory with the **`Dockerfile`**, **`docker-compose.yml`**, and **`devcontainer.json`**, open your project in VSCode.
- VSCode may prompt you to reopen the project in a container. If not, you can manually do so by opening the Command Palette (**`F1`** or **`Ctrl+Shift+P`**/**`Cmd+Shift+P`**) and selecting "Remote-Containers: Reopen in Container".
- This will build your Docker container as defined, including the necessary GPU assignments for CUDA development.

# **3. Development Using Devcontainers on a Remote Machine (SSH)**

Running your development environment on a remote machine can provide significant performance benefits, especially for resource-intensive tasks. This setup requires a bit more initial configuration but has substantial advantages of powerful remote resources and a consistent development environment, like the DGX-2 machines.

## **Prerequisites**

- The remote machine must have Docker installed and running. (This is typically already done unless its your own remote machine)
- SSH access to the remote machine is set up (refer to the SSH setup guide provided earlier).
- VSCode and the Remote Development extension pack are installed on your local machine.

## **Setting Up Your Remote Devcontainer Environment**

1. **Connect to Your Remote Machine via SSH**: Open VSCode, then open the Command Palette and select "Remote-SSH: Connect to Host...". Choose your remote machine from the list or add a new SSH connection.
2. **Initialize Your Project on the Remote Machine**: You can clone your repository or access your project files on the remote machine. This might involve using Git commands within the terminal in VSCode once connected to the remote machine.
3. **Configure the Devcontainer**: Similar to the local setup, create a **`.devcontainer`** directory in your project on the remote machine with a **`Dockerfile`** and **`devcontainer.json`**. These files might already exist if you cloned a repository already configured for Devcontainer development.
4. **Open Your Project in a Container Over SSH**: With the remote SSH connection active and your project open in VSCode, use the Command Palette to select "Remote-Containers: Reopen in Container". This will build and start the container on the remote machine, with VSCode connecting to it over SSH.
5. **Start Developing Remotely**: You can now develop directly on the remote machine, utilizing its resources while benefiting from a consistent, containerized environment controlled by your Devcontainer configuration.
File renamed without changes.
Loading
Loading