Skip to content

Commit 3f949ae

Browse files
authored
Merge pull request #1 from rabea-al/rabea/lock_requirements
Pytorch Component library maintenance
2 parents 8a49889 + 9c1aba4 commit 3f949ae

File tree

8 files changed

+1766
-1603
lines changed

8 files changed

+1766
-1603
lines changed

.github/workflows/run-workflow-tests.yml

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,35 @@ on:
55
branches: [ main ]
66
pull_request:
77
branches: "*"
8+
workflow_dispatch:
89

910
jobs:
1011
build-and-run:
1112
runs-on: ubuntu-latest
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
python-version: ["3.9", "3.10", "3.11"]
1217
env:
1318
TEST_XIRCUITS: |
1419
examples/PytorchTrainModel.xircuits
1520
examples/PytorchPredictFromModel.xircuits
1621
examples/PytorchTrainCustomNN.xircuits
17-
1822
steps:
1923
- name: Checkout Repository
2024
uses: actions/checkout@v3
2125

22-
- name: Install xircuits
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v4
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
31+
- name: Create virtual environment
32+
run: |
33+
python -m venv venv
34+
echo "${{ github.workspace }}/venv/bin" >> $GITHUB_PATH
35+
36+
- name: Install xircuits in virtual environment
2337
run: pip install xircuits
2438

2539
- name: Set Environment Variables
@@ -28,20 +42,24 @@ jobs:
2842
echo "LIBRARY_NAME=$LIBRARY_NAME" >> $GITHUB_ENV
2943
COMPONENT_LIBRARY_PATH="xai_components/${LIBRARY_NAME}"
3044
echo "COMPONENT_LIBRARY_PATH=$COMPONENT_LIBRARY_PATH" >> $GITHUB_ENV
45+
if [ "${{ github.event_name }}" == "pull_request" ]; then
46+
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
47+
else
48+
echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
49+
fi
3150
3251
- name: List Xircuits
33-
run: xircuits list
52+
run: xircuits list
3453

3554
- name: Clone Repository
3655
run: |
37-
# as of 1.9, xai_pytorch still lives in the base xircuits installation
3856
rm -rf ${{ env.COMPONENT_LIBRARY_PATH }}
39-
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
40-
git clone https://github.com/${{ github.repository }} ${{ env.COMPONENT_LIBRARY_PATH }}
57+
if [ "${{ github.event_name }}" == "pull_request" ]; then
58+
REPO_URL="${{ github.event.pull_request.head.repo.clone_url }}"
4159
else
42-
PR_BRANCH=${{ github.event.pull_request.head.ref }}
43-
git clone -b $PR_BRANCH https://github.com/${{ github.repository }} ${{ env.COMPONENT_LIBRARY_PATH }}
60+
REPO_URL="https://github.com/${{ github.repository }}"
4461
fi
62+
git clone -b ${{ env.BRANCH_NAME }} $REPO_URL ${{ env.COMPONENT_LIBRARY_PATH }}
4563
4664
- name: Install Component Library
4765
run: |
@@ -51,12 +69,15 @@ jobs:
5169
else
5270
echo "requirements.txt not found."
5371
fi
54-
72+
5573
- name: Test .xircuits Workflows
5674
run: |
5775
export PYTHONPATH="${GITHUB_WORKSPACE}:${PYTHONPATH}"
5876
LOG_FILE="${GITHUB_WORKSPACE}/workflow_logs.txt"
5977
TEST_FILES=$(echo "$TEST_XIRCUITS" | tr '\n' ' ')
78+
echo "Repository: $LIBRARY_NAME" > $LOG_FILE
79+
echo "Branch: $BRANCH_NAME" >> $LOG_FILE
80+
echo -e "Testing Files:\n$TEST_FILES" >> $LOG_FILE
6081
IFS=' ' read -r -a FILE_ARRAY <<< "$TEST_FILES"
6182
FAIL=0
6283
if [ ${#FILE_ARRAY[@]} -eq 0 ]; then
@@ -66,7 +87,7 @@ jobs:
6687
FULL_PATH="${COMPONENT_LIBRARY_PATH}/${file}"
6788
if [ -f "$FULL_PATH" ]; then
6889
WORKFLOW_LOG_FILE="${FULL_PATH%.*}_workflow_log.txt"
69-
echo "\n\nProcessing $FULL_PATH..." | tee -a $LOG_FILE
90+
echo -e "\n\nProcessing $FULL_PATH..." | tee -a $LOG_FILE
7091
xircuits compile $FULL_PATH "${FULL_PATH%.*}.py" 2>&1 | tee -a $LOG_FILE
7192
python "${FULL_PATH%.*}.py" 2>&1 | tee -a $WORKFLOW_LOG_FILE
7293
LAST_LINE=$(tail -n 1 "$WORKFLOW_LOG_FILE")
@@ -92,7 +113,7 @@ jobs:
92113
93114
- name: Upload log file
94115
if: always()
95-
uses: actions/upload-artifact@v3
116+
uses: actions/upload-artifact@v4
96117
with:
97-
name: workflow-logs
118+
name: ${{ env.LIBRARY_NAME }}-validation-workflow-${{ matrix.python-version }}
98119
path: ${{ github.workspace }}/workflow_logs.txt

README.md

Lines changed: 98 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,109 @@
1-
# Xircuits Comprehensive PyTorch Libraries
1+
2+
3+
<p align="center">
4+
<a href="https://github.com/XpressAI/xircuits/tree/master/xai_components#xircuits-component-library-list">Component Libraries</a> •
5+
<a href="https://github.com/XpressAI/xircuits/tree/master/project-templates#xircuits-project-templates-list">Project Templates</a>
6+
<br>
7+
<a href="https://xircuits.io/">Docs</a> •
8+
<a href="https://xircuits.io/docs/Installation">Install</a> •
9+
<a href="https://xircuits.io/docs/category/tutorials">Tutorials</a> •
10+
<a href="https://xircuits.io/docs/category/developer-guide">Developer Guides</a> •
11+
<a href="https://github.com/XpressAI/xircuits/blob/master/CONTRIBUTING.md">Contribute</a> •
12+
<a href="https://www.xpress.ai/blog/">Blog</a> •
13+
<a href="https://discord.com/invite/vgEg2ZtxCw">Discord</a>
14+
</p>
15+
16+
17+
18+
19+
20+
21+
<p align="center"><i>Xircuits Component Library for integrating PyTorch! Build and deploy machine learning models with ease.</i></p>
22+
23+
## Xircuits Comprehensive PyTorch Libraries
224

325
These libraries collectively provide extensive functionalities for integrating PyTorch into Xircuits workflows, encompassing both general PyTorch operations and neural network-specific tasks.
426

5-
### Installation
27+
## Table of Contents
28+
29+
- [Prerequisites](#prerequisites)
30+
- [Installation](#installation)
31+
- [Getting Started with PyTorch XAI Components](#getting-started-with-pytorch-xai-components)
32+
- [Try The Examples](#try-the-examples)
33+
- [Components Overview](#components-overview)
34+
- [Contributing](#contributing)
35+
36+
## Prerequisites
37+
38+
Before using this library, you’ll need the following:
39+
40+
1. **Python 3.8** or higher
41+
2. **Xircuits**
42+
3. The following Python packages:
43+
- **torch**
44+
- **torchvision**
45+
- **pillow**
46+
47+
48+
## Installation
49+
50+
To use this component library, ensure that you have an existing [Xircuits setup](https://xircuits.io/docs/main/Installation). You can then install the PyTorch library using the [component library interface](https://xircuits.io/docs/component-library/installation#installation-using-the-xircuits-library-interface), or through the CLI using:
51+
652

7-
To use this component library in Xircuits, simply run the Xircuits install command in your working directory.
853
```bash
954
xircuits install pytorch
1055
```
1156

12-
Alternatively, you may also clone this repository into your `xai_components` directory and install it manually via
57+
Alternatively, you may clone this repository into your `xai_components` directory and install it manually:
58+
59+
```bash
60+
# To clone the PyTorch component library into your Xircuits project directory
61+
git clone https://github.com/XpressAI/xai-pytorch.git xai_components/xai_pytorch
1362
```
14-
pip install -r requirements.txt
63+
```bash
64+
# Install required dependencies
65+
pip install -r xai_components/xai_pytorch/requirements.txt
1566
```
1667

17-
## Xircuits PyTorch Component Library
18-
Core components essential for developing and deploying machine learning models using PyTorch in Xircuits, covering tasks from data preparation to model evaluation.
19-
20-
### Components
21-
- **LoadTorchVisionDataset**: Loads Torch Vision datasets like MNIST and CIFAR.
22-
- **TorchDataLoader**: Creates DataLoader instances for efficient batch processing.
23-
- **ExampleTorchModelConfig**: Sets up an example Torch model with configurable parameters.
24-
- **TrainTorchModel**: Trains a Torch model with a given DataLoader and configuration.
25-
- **TestTorchModel**: Tests a trained Torch model for performance evaluation.
26-
- **SaveTorchModelState**: Saves the state of a trained Torch model.
27-
- **LoadTorchModelState**: Loads a saved Torch model's state.
28-
- **TorchModelPredict**: Performs predictions using a trained Torch model.
29-
- **Image2TorchTensor**: Converts images to Torch tensors for model input.
30-
- **TorchModelPredictFromTensor**: Predicts using a Torch model and tensor input.
31-
32-
## Xircuits PyTorch Neural Network Component Library
33-
34-
Designed for building and configuring neural network models in Xircuits. It offers flexibility in customizing architectures for various machine learning and deep learning tasks.
35-
36-
### Components
37-
- **TorchModel**: Builds custom Torch neural network models.
38-
- **TorchAddLinearLayer**: Adds linear layers to a model.
39-
- **TorchAddConv1DLayer** and **TorchAddConv2DLayer**: Integrates 1D and 2D convolutional layers.
40-
- **TorchAddTransformerEncoderLayer** and **TorchAddTransformerDecoderLayer**: Adds Transformer Encoder and Decoder layers.
41-
- **TorchLSTM**: Incorporates LSTM layers for sequence data.
42-
- **TorchAddReluLayer**: Adds ReLU activation layers.
43-
- **TorchAddDropoutLayer**: Includes dropout layers for regularization.
68+
## Getting Started With PyTorch XAI Components
69+
70+
After successfully installing the necessary libraries and components, you are ready to explore the PyTorch XAI Components Library. This library enables you to develop comprehensive machine learning workflows within Xircuits. Refer to the provided documentation and examples to master the integration, customization, and utilization of deep learning components using PyTorch XAI.
71+
72+
## Try The Examples
73+
74+
We have provided an example workflow to help you get started with the PyTorch XAI Components Library. Give it a try and see how you can create a custom deep learning workflow for your projects.
75+
76+
### PytorchTrainModel
77+
78+
This example demonstrates the initial setup of a machine learning workflow in Xircuits using the PyTorch XAI Components Library. It involves training a custom neural network model on your dataset. This step is crucial as the output model will be used in subsequent examples.
79+
80+
### PytorchPredictFromModel
81+
82+
Following the training process, this example shows how to use the trained model to make predictions. It leverages the model trained by the `PytorchTrainModel` to demonstrate the prediction process on new data, showcasing how to integrate trained models into practical applications.
83+
84+
### PytorchTrainCustomNN
85+
86+
This example extends the capabilities of the PyTorch XAI Components by illustrating how to train a more complex, custom neural network. It utilizes advanced features of PyTorch to tailor a neural network to specific needs beyond standard models.
87+
88+
**Note:** It is important to run the `PytorchTrainModel` example first, as the other examples depend on the output from this initial training step.
89+
90+
91+
## Components Overview
92+
93+
The PyTorch XAI Components Library offers an array of components tailored for various stages of the deep learning lifecycle. Explore these components and refer to their documentation to enhance your ability to develop sophisticated deep learning workflows.
94+
95+
## Contributing
96+
97+
We welcome contributions to the **Pytorch XAI Components Library**! If you would like to contribute:
98+
99+
1. Fork the repository.
100+
2. Create a new branch for your feature or bug fix.
101+
3. Open a pull request with a detailed description of your changes.
102+
103+
Please feel free to suggest new components, improvements, or optimizations. If you encounter any issues or have ideas for enhancements, you can open an issue in the repository.
104+
105+
---
106+
107+
### License
108+
109+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for more information.

0 commit comments

Comments
 (0)