Skip to content
Merged
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
54 changes: 54 additions & 0 deletions .github/classroom/autograding.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"tests": [
{
"name": "Style",
"setup": "python -m venv .venv; . .venv/bin/activate; pip3 install -qe .[dev]; pip3 install -q pre-commit",
"run": ". .venv/bin/activate && pre-commit run --all",
"input": "",
"output": "",
"comparison": "included",
"timeout": 10,
"points": 10
},
{
"name": "Task 2.1",
"setup": "sudo -H pip3 install -qe .",
"run": "pytest -m task2_1",
"input": "",
"output": "",
"comparison": "included",
"timeout": 10,
"points": 10
},
{
"name": "Task 2.2",
"setup": "sudo -H pip3 install -qe .",
"run": "pytest -m task2_2",
"input": "",
"output": "",
"comparison": "included",
"timeout": 10,
"points": 10
},
{
"name": "Task 2.3",
"setup": "sudo -H pip3 install -qe .",
"run": "pytest -m task2_3",
"input": "",
"output": "",
"comparison": "included",
"timeout": 10,
"points": 10
},
{
"name": "Task 2.4",
"setup": "sudo -H pip3 install -qe .",
"run": "pytest -m task2_4",
"input": "",
"output": "",
"comparison": "included",
"timeout": 10,
"points": 10
}
]
}
16 changes: 16 additions & 0 deletions .github/workflows/classroom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: GitHub Classroom Workflow

on: [push]

permissions:
checks: write
actions: read
contents: read

jobs:
build:
name: Autograding
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: education/autograding@v1
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,5 @@ dmypy.json
.pyre/
*.\#*
data/
pyodide
pyodideModule2.md
module2-modernization.md
45 changes: 14 additions & 31 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
repos:
# Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.3.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand All @@ -25,38 +25,21 @@ repos:
- id: check-toml
- id: debug-statements
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/timothycrosley/isort
rev: 5.10.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.12.9
hooks:
- id: isort
# Run the linter.
- id: ruff-check
args: [ --fix ]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.971
- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.404
hooks:
- id: mypy
exclude: ^(docs/)|(project/)|(assignments/)|(project/interface/)


# Black, the code formatter, natively supports pre-commit
- repo: https://github.com/psf/black
rev: 22.6.0
hooks:
- id: black

# Flake8 also supports pre-commit natively (same author)
- repo: https://github.com/PyCQA/flake8
rev: 5.0.4
hooks:
- id: flake8
additional_dependencies:
- pep8-naming
exclude: ^(docs/)|(assignments/)|(project/interface/)

# Doc linters
- repo: https://github.com/terrencepreilly/darglint
rev: v1.8.1
hooks:
- id: darglint
- id: pyright
additional_dependencies:
- pytest
- hypothesis
57 changes: 53 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,66 @@

<img src="https://minitorch.github.io/minitorch.svg" width="50%">

**Tensors** - Extending Autodifferentiation to Multidimensional Arrays

* Docs: https://minitorch.github.io/

* Overview: https://minitorch.github.io/module2/module2/

This assignment requires the following files from the previous assignments. You can get these by running
## Overview

Module 2 introduces **Tensors** - multidimensional arrays that extend the scalar autodifferentiation system from Module 1. While the scalar system is correct, it's inefficient due to Python overhead. Tensors solve this by grouping operations together and enabling faster implementations.

## Installation

See [installation.md](installation.md) for detailed setup instructions.

## Quick Start

```bash
# Install dependencies
pip install -e ".[dev,extra]"

# Sync files from Module 1
python sync_previous_module.py ../Module-1 .

# Verify installation
python -c "import minitorch; print('Success!')"

# Run tests
pytest -m task2_1 # Tensor data and indexing
pytest -m task2_2 # Tensor broadcasting
pytest -m task2_3 # Tensor operations
pytest -m task2_4 # Tensor autodifferentiation

# Train tensor-based model
python project/run_tensor.py
```

## Tasks

- **Task 2.1**: Implement tensor data structures with indexing and strides
- **Task 2.2**: Implement tensor broadcasting for operations between different shapes
- **Task 2.3**: Implement tensor operations (map, zip, reduce) and mathematical functions
- **Task 2.4**: Extend autodifferentiation to work with tensors and broadcasting
- **Task 2.5**: Create tensor-based neural network training

## Testing

See [testing.md](testing.md) for detailed testing instructions.

## Files

This assignment requires the following files from Module 1. You can get these by running:

```bash
python sync_previous_module.py previous-module-dir current-module-dir
python sync_previous_module.py ../Module-1 .
```

The files that will be synced are:

minitorch/operators.py minitorch/module.py minitorch/autodiff.py minitorch/scalar.py minitorch/module.py project/run_manual.py project/run_scalar.py
- `minitorch/operators.py`
- `minitorch/module.py`
- `minitorch/autodiff.py`
- `minitorch/scalar.py`
- `project/run_manual.py`
- `project/run_scalar.py`
98 changes: 98 additions & 0 deletions installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
hide:
- navigation
---

# MiniTorch Module 2 Installation

MiniTorch requires Python 3.8 or higher. To check your version of Python, run:

```bash
>>> python --version
```

We recommend creating a global MiniTorch workspace directory that you will use
for all modules:

```bash
>>> mkdir workspace; cd workspace
```

## Environment Setup

We highly recommend setting up a *virtual environment*. The virtual environment lets you install packages that are only used for your assignments and do not impact the rest of the system.

**Option 1: Anaconda (Recommended)**
```bash
>>> conda create --name minitorch python # Run only once
>>> conda activate minitorch
>>> conda install llvmlite # For optimization
```

**Option 2: Venv**
```bash
>>> python -m venv venv # Run only once
>>> source venv/bin/activate
```

The first line should be run only once, whereas the second needs to be run whenever you open a new terminal to get started for the class. You can tell if it works by checking if your terminal starts with `(minitorch)` or `(venv)`.

## Getting the Code

Each assignment is distributed through a Git repo. Once you accept the assignment from GitHub Classroom, a personal repository under Cornell-Tech-ML will be created for you. You can then clone this repository to start working on your assignment.

```bash
>>> git clone {{ASSIGNMENT}}
>>> cd {{ASSIGNMENT}}
```

## Syncing Previous Module Files

Module 2 requires files from Module 0 and Module 1. Sync them using:

```bash
>>> python sync_previous_module.py <path-to-module-1> <path-to-current-module>
```

Example:
```bash
>>> python sync_previous_module.py ../Module-1 .
```

Replace `<path-to-module-1>` with the path to your Module 1 directory and `<path-to-current-module>` with `.` for the current directory.

This will copy the following required files:
- `minitorch/operators.py`
- `minitorch/module.py`
- `minitorch/autodiff.py`
- `minitorch/scalar.py`
- `tests/test_module.py`
- `tests/test_operators.py`
- `tests/test_autodiff.py`
- `tests/test_scalar.py`
- `project/run_manual.py`
- `project/run_scalar.py`

## Installation

Install all packages in your virtual environment:

```bash
>>> python -m pip install -e ".[dev,extra]"
```

## Verification

Make sure everything is installed by running:

```bash
>>> python -c "import minitorch; print('Success!')"
```

Verify that the tensor functionality is available:

```bash
>>> python -c "from minitorch import tensor; print('Module 2 ready!')"
```

You're ready to start Module 2!
Loading
Loading