pranamanam commited on
Commit
faed495
Β·
verified Β·
1 Parent(s): d379995

Update course index, dependencies, and Lecture 3 test paths

Browse files
Files changed (4) hide show
  1. .gitignore +5 -0
  2. README.md +51 -25
  3. requirements.txt +1 -0
  4. tests/test_examples.py +3 -3
.gitignore CHANGED
@@ -18,3 +18,8 @@ esm2_diffusion_outputs/
18
  # Local secrets must never be committed.
19
  .env
20
  .env.*
 
 
 
 
 
 
18
  # Local secrets must never be committed.
19
  .env
20
  .env.*
21
+
22
+ # Lecture 2 downloads and newly generated results.
23
+ data/
24
+ flow_matching_outputs/
25
+ !lecture_2/flow_unet_mnist.pt
README.md CHANGED
@@ -10,6 +10,8 @@ tags:
10
  - esm2
11
  - protein-generation
12
  - guidance
 
 
13
  ---
14
 
15
  # CIS 6270 Course Code
@@ -26,19 +28,22 @@ and implementation notes; additional directories will accompany later lectures.
26
 
27
  ## Lecture index
28
 
29
- | Lectures | Topics | Code and documentation |
30
  | --- | --- | --- |
31
- | 2 and 3 | Continuous generative models, flow matching, diffusion, and guidance | [Guide](lectures_02_03/README.md) Β· [Flow matching](lectures_02_03/esm2_flow_guidance.py) Β· [Diffusion](lectures_02_03/esm2_diffusion_guidance.py) |
 
32
 
33
  ## Installation
34
 
35
  Use Python 3.11, or another compatible Python version at least 3.10, in a new
36
- virtual environment. The current examples were tested with PyTorch 2.9.1 and
37
- Transformers 4.57.6, as specified in `requirements.txt`.
 
38
 
39
  ```bash
40
  git clone https://huggingface.co/ChatterjeeLab/CIS6270
41
  cd CIS6270
 
42
 
43
  python3 -m venv .venv
44
  source .venv/bin/activate
@@ -49,13 +54,41 @@ python -m pip install -r requirements.txt
49
  On Windows PowerShell, create the environment with `python -m venv .venv`
50
  and activate it with `.venv\Scripts\Activate.ps1`.
51
 
52
- ## Run the Lectures 2 and 3 examples
 
 
 
 
 
 
 
 
 
 
53
 
54
  From the repository root:
55
 
56
  ```bash
57
- python lectures_02_03/esm2_flow_guidance.py --epochs 200 --samples 8
58
- python lectures_02_03/esm2_diffusion_guidance.py --epochs 200 --samples 8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
  ```
60
 
61
  Both scripts train on ESM-2 residue embeddings and compare classifier-free
@@ -65,26 +98,18 @@ constrained decoder to compare the flow and diffusion implementations.
65
 
66
  The first run downloads the public ESM-2 checkpoint. Each script then writes
67
  generated sequences and model parameters to its own output directory.
68
- The [lecture guide](lectures_02_03/README.md) describes the data format, training
69
  and sampling settings, property calculations, normalization, and residue-count
70
  constraint, with commands for using a custom dataset.
71
 
72
  ## Repository organization
73
 
74
- ```text
75
- CIS6270/
76
- β”œβ”€β”€ README.md
77
- β”œβ”€β”€ requirements.txt
78
- β”œβ”€β”€ LICENSE
79
- β”œβ”€β”€ lectures_02_03/
80
- β”‚ β”œβ”€β”€ README.md
81
- β”‚ β”œβ”€β”€ esm2_flow_guidance.py
82
- β”‚ β”œβ”€β”€ esm2_diffusion_guidance.py
83
- β”‚ β”œβ”€β”€ esm2_example.csv
84
- β”‚ └── GUIDANCE_NOTES.md
85
- └── tests/
86
- └── test_examples.py
87
- ```
88
 
89
  Installation instructions and the lecture index are maintained at the
90
  repository root. Lecture-specific commands, mathematical explanations, and
@@ -96,12 +121,13 @@ references accompany the corresponding code.
96
  python -m unittest discover -s tests -v
97
  ```
98
 
99
- The current unit tests cover property annotations, scalarization weights, reward
100
  gradients, DDPM schedule indexing, and constrained decoding.
101
 
102
  ## License
103
 
104
  The repository code is distributed under the
105
  [MIT License](https://huggingface.co/ChatterjeeLab/CIS6270/blob/main/LICENSE).
106
- Pretrained model weights are downloaded from their original repositories
107
- under the corresponding distribution terms.
 
 
10
  - esm2
11
  - protein-generation
12
  - guidance
13
+ - mnist
14
+ - image-generation
15
  ---
16
 
17
  # CIS 6270 Course Code
 
28
 
29
  ## Lecture index
30
 
31
+ | Lecture | Topics | Code and documentation |
32
  | --- | --- | --- |
33
+ | 2 | Unconditional MNIST image generation with flow matching and a simple U-Net | [Guide](lecture_2/README.md) Β· [Script](lecture_2/flow_matching_unet_lecture.py) Β· [Saved checkpoint](https://huggingface.co/ChatterjeeLab/CIS6270/resolve/main/lecture_2/flow_unet_mnist.pt?download=true) |
34
+ | 3 | Flow matching, diffusion, and guidance for ESM-2 residue embeddings | [Guide](lecture_3/README.md) Β· [Flow matching](lecture_3/esm2_flow_guidance.py) Β· [Diffusion](lecture_3/esm2_diffusion_guidance.py) |
35
 
36
  ## Installation
37
 
38
  Use Python 3.11, or another compatible Python version at least 3.10, in a new
39
+ virtual environment. The shared `requirements.txt` pins PyTorch 2.9.1,
40
+ TorchVision 0.24.1, and Transformers 4.57.6. Lecture 2 uses PyTorch and
41
+ TorchVision; Lecture 3 also uses Transformers.
42
 
43
  ```bash
44
  git clone https://huggingface.co/ChatterjeeLab/CIS6270
45
  cd CIS6270
46
+ git lfs pull
47
 
48
  python3 -m venv .venv
49
  source .venv/bin/activate
 
54
  On Windows PowerShell, create the environment with `python -m venv .venv`
55
  and activate it with `.venv\Scripts\Activate.ps1`.
56
 
57
+ The saved checkpoint uses Git LFS. If Git LFS is unavailable, download
58
+ [flow_unet_mnist.pt](https://huggingface.co/ChatterjeeLab/CIS6270/resolve/main/lecture_2/flow_unet_mnist.pt?download=true)
59
+ directly and place it in `lecture_2/`. Training from scratch does not require
60
+ the saved checkpoint.
61
+
62
+ ## Lecture 2: MNIST flow matching
63
+
64
+ Lecture 2 contains one self-contained, commented script. It downloads MNIST,
65
+ loads batches of normalized images, defines a small U-Net velocity network,
66
+ trains it with conditional flow matching, and generates images from Gaussian
67
+ noise using Euler integration.
68
 
69
  From the repository root:
70
 
71
  ```bash
72
+ python lecture_2/flow_matching_unet_lecture.py
73
+ ```
74
+
75
+ The default run trains for 20 epochs and writes `samples.png`, `trajectory.png`,
76
+ and a new `flow_unet_mnist.pt` to `flow_matching_outputs/`. The script selects
77
+ CUDA, Apple MPS, or CPU according to availability. Its numbered `# %%` sections
78
+ match the lecture walkthrough.
79
+
80
+ The bundled [checkpoint](lecture_2/flow_unet_mnist.pt) has **5 completed epochs**
81
+ on all 60,000 MNIST training images. The [Lecture 2 guide](lecture_2/README.md)
82
+ includes a short example for loading it and generating images without training,
83
+ along with selected generated digits and their noise-to-image trajectories.
84
+
85
+ ## Lecture 3: Flow and diffusion guidance
86
+
87
+ From the repository root:
88
+
89
+ ```bash
90
+ python lecture_3/esm2_flow_guidance.py --epochs 200 --samples 8
91
+ python lecture_3/esm2_diffusion_guidance.py --epochs 200 --samples 8
92
  ```
93
 
94
  Both scripts train on ESM-2 residue embeddings and compare classifier-free
 
98
 
99
  The first run downloads the public ESM-2 checkpoint. Each script then writes
100
  generated sequences and model parameters to its own output directory.
101
+ The [lecture guide](lecture_3/README.md) describes the data format, training
102
  and sampling settings, property calculations, normalization, and residue-count
103
  constraint, with commands for using a custom dataset.
104
 
105
  ## Repository organization
106
 
107
+ | Location | Contents |
108
+ | --- | --- |
109
+ | Repository root | Course index, installation requirements, and license |
110
+ | [`lecture_2/`](https://huggingface.co/ChatterjeeLab/CIS6270/tree/main/lecture_2) | One MNIST flow-matching script, guide, trained checkpoint, and selected example images |
111
+ | [`lecture_3/`](https://huggingface.co/ChatterjeeLab/CIS6270/tree/main/lecture_3) | ESM-2 flow and diffusion guidance scripts, sequence data, guide, and mathematical notes |
112
+ | [`tests/`](https://huggingface.co/ChatterjeeLab/CIS6270/tree/main/tests) | Offline checks for the Lecture 3 examples |
 
 
 
 
 
 
 
 
113
 
114
  Installation instructions and the lecture index are maintained at the
115
  repository root. Lecture-specific commands, mathematical explanations, and
 
121
  python -m unittest discover -s tests -v
122
  ```
123
 
124
+ The Lecture 3 unit tests cover property annotations, scalarization weights, reward
125
  gradients, DDPM schedule indexing, and constrained decoding.
126
 
127
  ## License
128
 
129
  The repository code is distributed under the
130
  [MIT License](https://huggingface.co/ChatterjeeLab/CIS6270/blob/main/LICENSE).
131
+ The Lecture 2 U-Net checkpoint is included under the same license. The Lecture 3
132
+ ESM-2 weights are downloaded from their original repository under the
133
+ corresponding distribution terms.
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  # Tested teaching environment: Python 3.11.
2
  torch==2.9.1
 
3
  transformers==4.57.6
 
1
  # Tested teaching environment: Python 3.11.
2
  torch==2.9.1
3
+ torchvision==0.24.1
4
  transformers==4.57.6
tests/test_examples.py CHANGED
@@ -1,4 +1,4 @@
1
- """Offline unit checks for the Lectures 2 and 3 examples."""
2
  import csv
3
  import itertools
4
  from pathlib import Path
@@ -9,7 +9,7 @@ import unittest
9
  import torch
10
 
11
  ROOT = Path(__file__).resolve().parents[1]
12
- sys.path.insert(0, str(ROOT / "lectures_02_03"))
13
  import esm2_flow_guidance as flow
14
  import esm2_diffusion_guidance as diffusion
15
 
@@ -20,7 +20,7 @@ class GuidanceTests(unittest.TestCase):
20
  torch.set_num_threads(2)
21
 
22
  def test_example_annotations(self):
23
- with (ROOT / "lectures_02_03" / "esm2_example.csv").open(newline="") as handle:
24
  rows = list(csv.DictReader(handle))
25
  self.assertEqual(len(rows), 64)
26
  self.assertEqual({len(row["sequence"]) for row in rows}, {24})
 
1
+ """Offline unit checks for the Lecture 3 examples."""
2
  import csv
3
  import itertools
4
  from pathlib import Path
 
9
  import torch
10
 
11
  ROOT = Path(__file__).resolve().parents[1]
12
+ sys.path.insert(0, str(ROOT / "lecture_3"))
13
  import esm2_flow_guidance as flow
14
  import esm2_diffusion_guidance as diffusion
15
 
 
20
  torch.set_num_threads(2)
21
 
22
  def test_example_annotations(self):
23
+ with (ROOT / "lecture_3" / "esm2_example.csv").open(newline="") as handle:
24
  rows = list(csv.DictReader(handle))
25
  self.assertEqual(len(rows), 64)
26
  self.assertEqual({len(row["sequence"]) for row in rows}, {24})