floydnet 0.1.0__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {floydnet-0.1.0 → floydnet-0.1.1}/.gitignore +11 -0
- floydnet-0.1.1/CHANGELOG.md +12 -0
- {floydnet-0.1.0 → floydnet-0.1.1}/PKG-INFO +141 -28
- floydnet-0.1.1/README.md +159 -0
- floydnet-0.1.1/example/README.md +129 -0
- {floydnet-0.1.0 → floydnet-0.1.1}/pyproject.toml +2 -2
- floydnet-0.1.0/CHANGELOG.md +0 -7
- floydnet-0.1.0/README.md +0 -46
- floydnet-0.1.0/paper/README.md +0 -11
- {floydnet-0.1.0 → floydnet-0.1.1}/CITATION.cff +0 -0
- {floydnet-0.1.0 → floydnet-0.1.1}/LICENSE +0 -0
|
@@ -205,3 +205,14 @@ cython_debug/
|
|
|
205
205
|
marimo/_static/
|
|
206
206
|
marimo/_lsp/
|
|
207
207
|
__marimo__/
|
|
208
|
+
|
|
209
|
+
example/data/count/processed/
|
|
210
|
+
example/data/count/hom.npy
|
|
211
|
+
example/data/count/iso.npy
|
|
212
|
+
example/wandb
|
|
213
|
+
example/output
|
|
214
|
+
example/outputs
|
|
215
|
+
.github/
|
|
216
|
+
count.out
|
|
217
|
+
run_scripts
|
|
218
|
+
example/data/TSP
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
## [1.0.0] - 2026-01-25
|
|
6
|
+
- Full release with training and evaluation scripts for Graph Count, BREC, and TSP.
|
|
7
|
+
- Added `pivotal_attention3` functional API for 3-Floyd attention.
|
|
8
|
+
- Added additional configuration options in `PivotalAttentionBlock`.
|
|
9
|
+
|
|
10
|
+
## [0.1.0] - 2025-10-21
|
|
11
|
+
- Initial public skeleton with module + functional attention
|
|
12
|
+
- examples scaffolding
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: floydnet
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.1
|
|
4
4
|
Summary: Floyd Multi-Head Attention: a drop-in variant of PyTorch MHA with module and function APIs
|
|
5
5
|
Project-URL: Homepage, https://github.com/ocx-lab/FloydNet
|
|
6
6
|
Project-URL: Repository, https://github.com/ocx-lab/FloydNet
|
|
@@ -230,49 +230,162 @@ Requires-Dist: pytest>=7.4; extra == 'dev'
|
|
|
230
230
|
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
231
231
|
Description-Content-Type: text/markdown
|
|
232
232
|
|
|
233
|
-
#
|
|
233
|
+
# FloydNet
|
|
234
234
|
|
|
235
|
-
|
|
235
|
+
Official implementation of an ICLR paper (TODO: add paper title, authors, and links/arXiv).
|
|
236
236
|
|
|
237
|
-
|
|
238
|
-
- Functional API: `floyd_scaled_dot_product_attention` mirroring `torch.nn.functional.scaled_dot_product_attention`
|
|
237
|
+

|
|
239
238
|
|
|
240
|
-
|
|
239
|
+
This repository serves two audiences:
|
|
241
240
|
|
|
242
|
-
|
|
241
|
+
- **Engineering users**: reusable PyTorch components (functional attention APIs and Transformer-style blocks) under `src/`.
|
|
242
|
+
- **Research users**: scripts/configs to reproduce paper experiments under `example/`.
|
|
243
243
|
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Introduction
|
|
247
|
+
|
|
248
|
+
FloydNet is the official PyTorch implementation accompanying an ICLR paper (TODO).
|
|
249
|
+
The repository provides:
|
|
250
|
+
|
|
251
|
+
1. **Reusable components**: a drop-in attention/Transformer-block interface intended for integration into existing projects.
|
|
252
|
+
2. **Reproduction code**: end-to-end training/evaluation pipelines to reproduce the benchmarks reported in the paper.
|
|
253
|
+
|
|
254
|
+
For algorithmic details, hyperparameter choices, and analysis, please refer to the paper (TODO: link).
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## Repository Structure
|
|
259
|
+
|
|
260
|
+
- `src/floydnet/`
|
|
261
|
+
**Library code for reuse**
|
|
262
|
+
Contains the functional attention API and module/block implementations.
|
|
263
|
+
|
|
264
|
+
- `example/`
|
|
265
|
+
**Experiment reproduction code**
|
|
266
|
+
Includes benchmark-specific scripts, configs, and data preparation utilities.
|
|
267
|
+
|
|
268
|
+
---
|
|
269
|
+
|
|
270
|
+
## Using the Attention / Transformer Block
|
|
271
|
+
|
|
272
|
+
This section targets **engineering users** who want to import FloydNet as a dependency.
|
|
273
|
+
|
|
274
|
+
### Installation
|
|
275
|
+
|
|
276
|
+
#### Option A: Install from PyPI
|
|
244
277
|
```bash
|
|
245
|
-
|
|
246
|
-
uv venv --python 3.10
|
|
247
|
-
source .venv/bin/activate
|
|
248
|
-
uv pip install -e .[dev]
|
|
278
|
+
pip install floydnet
|
|
249
279
|
```
|
|
250
280
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
281
|
+
#### Option B: Install from source
|
|
282
|
+
```bash
|
|
283
|
+
git clone git@github.com:ocx-lab/FloydNet.git
|
|
284
|
+
cd FloydNet
|
|
285
|
+
pip install -e .
|
|
286
|
+
```
|
|
254
287
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
288
|
+
> Requirements: Python `>= 3.9`, PyTorch `>= 2.1` (see `pyproject.toml`).
|
|
289
|
+
|
|
290
|
+
### Public API
|
|
291
|
+
|
|
292
|
+
FloydNet re-exports the public API from `src/floydnet/__init__.py`, so you can import from the top-level package:
|
|
293
|
+
|
|
294
|
+
- **Functional API**:
|
|
295
|
+
- `pivotal_attention` (see `src/floydnet/functional.py`)
|
|
296
|
+
- **Module / block API**:
|
|
297
|
+
- `PivotalAttentionBlock` (see `src/floydnet/transformer.py`)
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
from floydnet import pivotal_attention, PivotalAttentionBlock
|
|
259
301
|
```
|
|
260
302
|
|
|
261
|
-
###
|
|
303
|
+
### Minimal usage example
|
|
304
|
+
|
|
262
305
|
```python
|
|
263
306
|
import torch
|
|
264
|
-
import
|
|
265
|
-
|
|
307
|
+
from floydnet import pivotal_attention, PivotalAttentionBlock
|
|
308
|
+
|
|
309
|
+
# -------------------------
|
|
310
|
+
# Module API (Transformer-style block)
|
|
311
|
+
# Input is a 2D grid: (B, N, N, C)
|
|
312
|
+
# -------------------------
|
|
313
|
+
B, N, C = 2, 16, 64
|
|
314
|
+
x = torch.randn(B, N, N, C)
|
|
266
315
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
v = torch.randn(2, 8, 16, 64)
|
|
270
|
-
out = floyd_scaled_dot_product_attention(q, k, v)
|
|
316
|
+
m = PivotalAttentionBlock(embed_dim=C, num_heads=8, dropout=0.0)
|
|
317
|
+
out = m(x) # (B, N, N, C)
|
|
271
318
|
print(out.shape)
|
|
319
|
+
|
|
320
|
+
# -------------------------
|
|
321
|
+
# Functional API
|
|
322
|
+
# All inputs are 5D: (B, H, N, N, D)
|
|
323
|
+
# -------------------------
|
|
324
|
+
B, H, N, D = 2, 8, 16, 64
|
|
325
|
+
q_ik = torch.randn(B, H, N, N, D)
|
|
326
|
+
k_ij = torch.randn(B, H, N, N, D)
|
|
327
|
+
k_jk = torch.randn(B, H, N, N, D)
|
|
328
|
+
v_ij = torch.randn(B, H, N, N, D)
|
|
329
|
+
v_jk = torch.randn(B, H, N, N, D)
|
|
330
|
+
|
|
331
|
+
y = pivotal_attention(q_ik, k_ij, k_jk, v_ij, v_jk) # (B, H, N, N, D)
|
|
332
|
+
print(y.shape)
|
|
272
333
|
```
|
|
273
334
|
|
|
274
|
-
|
|
275
|
-
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## Reproducing Paper Results
|
|
338
|
+
|
|
339
|
+
This section targets **research users** who want to reproduce the experiments in the paper.
|
|
340
|
+
|
|
341
|
+
See `example/README.md` For detailed description.
|
|
342
|
+
|
|
343
|
+
### Environment setup
|
|
344
|
+
|
|
345
|
+
We recommend using `uv` to create an isolated environment for the reproduction code under `example/`.
|
|
346
|
+
|
|
347
|
+
```bash
|
|
348
|
+
cd /path/to/FloydNet
|
|
349
|
+
|
|
350
|
+
# 1) Create a uv virtual environment with Python 3.12
|
|
351
|
+
uv venv --python 3.12
|
|
352
|
+
|
|
353
|
+
# 2) Activate it
|
|
354
|
+
source .venv/bin/activate
|
|
355
|
+
|
|
356
|
+
# 3) Install extra dependencies for reproducing paper experiments
|
|
357
|
+
uv pip install -r example/requirements.txt
|
|
358
|
+
|
|
359
|
+
# 4) Install FloydNet (editable) for local development / imports
|
|
360
|
+
uv pip install -e .
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## Changelog (latest)
|
|
364
|
+
|
|
365
|
+
- Full release with training and evaluation scripts for Graph Count, BREC, and TSP.
|
|
366
|
+
- Added `pivotal_attention3` functional API for 3-Floyd attention.
|
|
367
|
+
- Added additional configuration options in `PivotalAttentionBlock`.
|
|
368
|
+
|
|
369
|
+
The full changelog is in [CHANGELOG.md](CHANGELOG.md).
|
|
370
|
+
|
|
371
|
+
## Citation
|
|
372
|
+
|
|
373
|
+
If you use this code in your research, please cite the paper:
|
|
374
|
+
|
|
375
|
+
```bibtex
|
|
376
|
+
@inproceedings{TODO,
|
|
377
|
+
title = {TODO},
|
|
378
|
+
author = {TODO},
|
|
379
|
+
booktitle = {International Conference on Learning Representations (ICLR)},
|
|
380
|
+
year = {TODO},
|
|
381
|
+
url = {TODO}
|
|
382
|
+
}
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
(Alternatively, see [CITATION.cff](CITATION.cff).)
|
|
386
|
+
|
|
387
|
+
---
|
|
276
388
|
|
|
277
389
|
## License
|
|
278
|
-
|
|
390
|
+
|
|
391
|
+
This project is licensed under the **Apache License 2.0**. See [LICENSE](LICENSE).
|
floydnet-0.1.1/README.md
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# FloydNet
|
|
2
|
+
|
|
3
|
+
Official implementation of an ICLR paper (TODO: add paper title, authors, and links/arXiv).
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
This repository serves two audiences:
|
|
8
|
+
|
|
9
|
+
- **Engineering users**: reusable PyTorch components (functional attention APIs and Transformer-style blocks) under `src/`.
|
|
10
|
+
- **Research users**: scripts/configs to reproduce paper experiments under `example/`.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Introduction
|
|
15
|
+
|
|
16
|
+
FloydNet is the official PyTorch implementation accompanying an ICLR paper (TODO).
|
|
17
|
+
The repository provides:
|
|
18
|
+
|
|
19
|
+
1. **Reusable components**: a drop-in attention/Transformer-block interface intended for integration into existing projects.
|
|
20
|
+
2. **Reproduction code**: end-to-end training/evaluation pipelines to reproduce the benchmarks reported in the paper.
|
|
21
|
+
|
|
22
|
+
For algorithmic details, hyperparameter choices, and analysis, please refer to the paper (TODO: link).
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Repository Structure
|
|
27
|
+
|
|
28
|
+
- `src/floydnet/`
|
|
29
|
+
**Library code for reuse**
|
|
30
|
+
Contains the functional attention API and module/block implementations.
|
|
31
|
+
|
|
32
|
+
- `example/`
|
|
33
|
+
**Experiment reproduction code**
|
|
34
|
+
Includes benchmark-specific scripts, configs, and data preparation utilities.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Using the Attention / Transformer Block
|
|
39
|
+
|
|
40
|
+
This section targets **engineering users** who want to import FloydNet as a dependency.
|
|
41
|
+
|
|
42
|
+
### Installation
|
|
43
|
+
|
|
44
|
+
#### Option A: Install from PyPI
|
|
45
|
+
```bash
|
|
46
|
+
pip install floydnet
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### Option B: Install from source
|
|
50
|
+
```bash
|
|
51
|
+
git clone git@github.com:ocx-lab/FloydNet.git
|
|
52
|
+
cd FloydNet
|
|
53
|
+
pip install -e .
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
> Requirements: Python `>= 3.9`, PyTorch `>= 2.1` (see `pyproject.toml`).
|
|
57
|
+
|
|
58
|
+
### Public API
|
|
59
|
+
|
|
60
|
+
FloydNet re-exports the public API from `src/floydnet/__init__.py`, so you can import from the top-level package:
|
|
61
|
+
|
|
62
|
+
- **Functional API**:
|
|
63
|
+
- `pivotal_attention` (see `src/floydnet/functional.py`)
|
|
64
|
+
- **Module / block API**:
|
|
65
|
+
- `PivotalAttentionBlock` (see `src/floydnet/transformer.py`)
|
|
66
|
+
|
|
67
|
+
```python
|
|
68
|
+
from floydnet import pivotal_attention, PivotalAttentionBlock
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Minimal usage example
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
import torch
|
|
75
|
+
from floydnet import pivotal_attention, PivotalAttentionBlock
|
|
76
|
+
|
|
77
|
+
# -------------------------
|
|
78
|
+
# Module API (Transformer-style block)
|
|
79
|
+
# Input is a 2D grid: (B, N, N, C)
|
|
80
|
+
# -------------------------
|
|
81
|
+
B, N, C = 2, 16, 64
|
|
82
|
+
x = torch.randn(B, N, N, C)
|
|
83
|
+
|
|
84
|
+
m = PivotalAttentionBlock(embed_dim=C, num_heads=8, dropout=0.0)
|
|
85
|
+
out = m(x) # (B, N, N, C)
|
|
86
|
+
print(out.shape)
|
|
87
|
+
|
|
88
|
+
# -------------------------
|
|
89
|
+
# Functional API
|
|
90
|
+
# All inputs are 5D: (B, H, N, N, D)
|
|
91
|
+
# -------------------------
|
|
92
|
+
B, H, N, D = 2, 8, 16, 64
|
|
93
|
+
q_ik = torch.randn(B, H, N, N, D)
|
|
94
|
+
k_ij = torch.randn(B, H, N, N, D)
|
|
95
|
+
k_jk = torch.randn(B, H, N, N, D)
|
|
96
|
+
v_ij = torch.randn(B, H, N, N, D)
|
|
97
|
+
v_jk = torch.randn(B, H, N, N, D)
|
|
98
|
+
|
|
99
|
+
y = pivotal_attention(q_ik, k_ij, k_jk, v_ij, v_jk) # (B, H, N, N, D)
|
|
100
|
+
print(y.shape)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
---
|
|
104
|
+
|
|
105
|
+
## Reproducing Paper Results
|
|
106
|
+
|
|
107
|
+
This section targets **research users** who want to reproduce the experiments in the paper.
|
|
108
|
+
|
|
109
|
+
See `example/README.md` For detailed description.
|
|
110
|
+
|
|
111
|
+
### Environment setup
|
|
112
|
+
|
|
113
|
+
We recommend using `uv` to create an isolated environment for the reproduction code under `example/`.
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
cd /path/to/FloydNet
|
|
117
|
+
|
|
118
|
+
# 1) Create a uv virtual environment with Python 3.12
|
|
119
|
+
uv venv --python 3.12
|
|
120
|
+
|
|
121
|
+
# 2) Activate it
|
|
122
|
+
source .venv/bin/activate
|
|
123
|
+
|
|
124
|
+
# 3) Install extra dependencies for reproducing paper experiments
|
|
125
|
+
uv pip install -r example/requirements.txt
|
|
126
|
+
|
|
127
|
+
# 4) Install FloydNet (editable) for local development / imports
|
|
128
|
+
uv pip install -e .
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Changelog (latest)
|
|
132
|
+
|
|
133
|
+
- Full release with training and evaluation scripts for Graph Count, BREC, and TSP.
|
|
134
|
+
- Added `pivotal_attention3` functional API for 3-Floyd attention.
|
|
135
|
+
- Added additional configuration options in `PivotalAttentionBlock`.
|
|
136
|
+
|
|
137
|
+
The full changelog is in [CHANGELOG.md](CHANGELOG.md).
|
|
138
|
+
|
|
139
|
+
## Citation
|
|
140
|
+
|
|
141
|
+
If you use this code in your research, please cite the paper:
|
|
142
|
+
|
|
143
|
+
```bibtex
|
|
144
|
+
@inproceedings{TODO,
|
|
145
|
+
title = {TODO},
|
|
146
|
+
author = {TODO},
|
|
147
|
+
booktitle = {International Conference on Learning Representations (ICLR)},
|
|
148
|
+
year = {TODO},
|
|
149
|
+
url = {TODO}
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
(Alternatively, see [CITATION.cff](CITATION.cff).)
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
This project is licensed under the **Apache License 2.0**. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
### Benchmarks
|
|
2
|
+
|
|
3
|
+
The paper reports results on **three benchmarks**:
|
|
4
|
+
|
|
5
|
+
- Graph Count
|
|
6
|
+
- BREC
|
|
7
|
+
- TSP
|
|
8
|
+
|
|
9
|
+
### Graph Count
|
|
10
|
+
|
|
11
|
+
The Graph Count benchmark and dataset construction follow:
|
|
12
|
+
https://github.com/subgraph23/homomorphism-expressivity
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
source .venv/bin/activate
|
|
16
|
+
cd example
|
|
17
|
+
python -m data.count.process_data
|
|
18
|
+
./count/run.sh
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### BREC
|
|
22
|
+
|
|
23
|
+
The BREC benchmark and dataset construction follow:
|
|
24
|
+
https://github.com/GraphPKU/BREC
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
source .venv/bin/activate
|
|
28
|
+
cd example/data/BREC/raw
|
|
29
|
+
unzip BREC_data_all.zip
|
|
30
|
+
|
|
31
|
+
# Back to the example folder
|
|
32
|
+
cd ../../..
|
|
33
|
+
|
|
34
|
+
# Reproduce FloydNet results
|
|
35
|
+
python -m BREC.test_BREC
|
|
36
|
+
|
|
37
|
+
# Reproduce 3-Floyd results
|
|
38
|
+
python -m BREC.test_BREC --floyd_level 3
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### TSP
|
|
42
|
+
|
|
43
|
+
Reproducing TSP at full scale is computationally heavy and involves large datasets. For convenience, we provide:
|
|
44
|
+
|
|
45
|
+
- A small demo dataset on Hugging Face:
|
|
46
|
+
https://huggingface.co/datasets/ocxlabs/FloydNet_TSP_demo
|
|
47
|
+
- Pretrained checkpoints for:
|
|
48
|
+
- **Metric TSP** (Euclidean TSP, `euc`): https://huggingface.co/ocxlabs/FloydNet_TSP_euc
|
|
49
|
+
- **Non-metric TSP** (Explicit TSP, `exp`): https://huggingface.co/ocxlabs/FloydNet_TSP_exp
|
|
50
|
+
|
|
51
|
+
This section describes **inference and evaluation** using the demo data and checkpoints.
|
|
52
|
+
|
|
53
|
+
#### Prepare demo data
|
|
54
|
+
|
|
55
|
+
Download the demo dataset as a `.zip`, unzip it, and place the extracted folder under `example/data/`.
|
|
56
|
+
|
|
57
|
+
#### Inference
|
|
58
|
+
|
|
59
|
+
Run inference in `--test_mode` using `torchrun` (the command below assumes **single-node, 8 GPUs**).
|
|
60
|
+
Set `--subset` and make sure `--load_checkpoint` matches the subset.
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
source .venv/bin/activate
|
|
64
|
+
cd example
|
|
65
|
+
|
|
66
|
+
torchrun \
|
|
67
|
+
--nproc_per_node=8 \
|
|
68
|
+
-m TSP.run \
|
|
69
|
+
--subset exp \
|
|
70
|
+
--output_dir ./outputs/TSP_exp \
|
|
71
|
+
--load_checkpoint path/to/TSP_exp/epoch_01000.pt \
|
|
72
|
+
--test_mode \
|
|
73
|
+
--split_factor 1 \
|
|
74
|
+
--sample_count_per_case 10
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
#### Evaluation
|
|
78
|
+
|
|
79
|
+
After inference finishes, aggregate results with:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
source .venv/bin/activate
|
|
83
|
+
cd example
|
|
84
|
+
|
|
85
|
+
python -m TSP.report ./outputs/TSP_exp
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
This saves CSV summaries (downsampled to 1 / 5 / 10 samples per instance) into the same `output_dir`.
|
|
89
|
+
|
|
90
|
+
#### Data generation
|
|
91
|
+
|
|
92
|
+
If you want to generate additional data (beyond the demo set) and train from scratch, prepare the raw `.npy` files as follows.
|
|
93
|
+
|
|
94
|
+
##### Metric TSP (Euclidean TSP, `euc`)
|
|
95
|
+
|
|
96
|
+
1. Randomly sample **N integer points** in 2D, $p_i = (x_i, y_i)$, and ensure **pairwise Euclidean distances ≤ 200**.
|
|
97
|
+
2. Solve the instance with a classic TSP solver (e.g., [Concorde](https://www.math.uwaterloo.ca/tsp/concorde.html)).
|
|
98
|
+
3. Reorder the points so that $p_0 \rightarrow p_1 \rightarrow ... \rightarrow p_{N-1}$ is the optimal tour.
|
|
99
|
+
4. Sample **T** instances for each **N**, stack them into a NumPy array of shape **`[T, N, 2]`** with dtype **`int8`**, and save grouped-by-N arrays as:
|
|
100
|
+
- `data/TSP/euc/non-uni/raw/{N:03d}.npy`
|
|
101
|
+
|
|
102
|
+
##### Non-metric TSP (Explicit TSP, `exp`)
|
|
103
|
+
|
|
104
|
+
1. Randomly sample an **N×N symmetric distance matrix** with **maximum value ≤ 200**.
|
|
105
|
+
2. Solve with a classic TSP solver (e.g., [Concorde](https://www.math.uwaterloo.ca/tsp/concorde.html)).
|
|
106
|
+
3. Reorder rows/columns so that $0 \rightarrow 1 \rightarrow ... \rightarrow N-1$ is the optimal tour.
|
|
107
|
+
4. Sample **T** instances for each **N**, stack them into a NumPy array of shape **`[T, N, N]`** with dtype **`int8`**, and save grouped-by-N arrays as:
|
|
108
|
+
- `data/TSP/exp/non-uni/raw/{N:03d}.npy`
|
|
109
|
+
|
|
110
|
+
#### Training from scratch
|
|
111
|
+
|
|
112
|
+
Recommended (paper-matching) training setup: 8 nodes × 8 GPUs = 64 GPUs total.
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
source .venv/bin/activate
|
|
116
|
+
cd example
|
|
117
|
+
torchrun \
|
|
118
|
+
--master_addr <MASTER_ADDR> \
|
|
119
|
+
--master_port <MASTER_PORT> \
|
|
120
|
+
--nnodes 8 \
|
|
121
|
+
--node_rank <NODE_RANK> \
|
|
122
|
+
--nproc_per_node 8 \
|
|
123
|
+
-m TSP.run \
|
|
124
|
+
--subset exp \
|
|
125
|
+
--output_dir ./outputs/TSP_exp \
|
|
126
|
+
--wandb_name TSP_exp
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
---
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "floydnet"
|
|
7
|
-
version = "0.1.
|
|
7
|
+
version = "0.1.1"
|
|
8
8
|
description = "Floyd Multi-Head Attention: a drop-in variant of PyTorch MHA with module and function APIs"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
@@ -54,7 +54,7 @@ include = [
|
|
|
54
54
|
]
|
|
55
55
|
|
|
56
56
|
[tool.hatch.build.targets.wheel]
|
|
57
|
-
packages = ["src/
|
|
57
|
+
packages = ["src/floydnet"]
|
|
58
58
|
|
|
59
59
|
[tool.ruff]
|
|
60
60
|
line-length = 100
|
floydnet-0.1.0/CHANGELOG.md
DELETED
floydnet-0.1.0/README.md
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# floyd-net
|
|
2
|
-
|
|
3
|
-
Floyd Multi-Head Attention (F-MHA) is a drop-in variant of PyTorch's attention stack. It provides:
|
|
4
|
-
|
|
5
|
-
- Module API: `FloydMultiheadAttention` mirroring `torch.nn.MultiheadAttention`
|
|
6
|
-
- Functional API: `floyd_scaled_dot_product_attention` mirroring `torch.nn.functional.scaled_dot_product_attention`
|
|
7
|
-
|
|
8
|
-
Install and manage with `uv` for a modern Python workflow.
|
|
9
|
-
|
|
10
|
-
## Quick start
|
|
11
|
-
|
|
12
|
-
```bash
|
|
13
|
-
# Install with uv (recommended)
|
|
14
|
-
uv venv --python 3.10
|
|
15
|
-
source .venv/bin/activate
|
|
16
|
-
uv pip install -e .[dev]
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
```python
|
|
20
|
-
import torch
|
|
21
|
-
from floyd_net import FloydMultiheadAttention
|
|
22
|
-
|
|
23
|
-
m = FloydMultiheadAttention(embed_dim=64, num_heads=8, batch_first=True)
|
|
24
|
-
x = torch.randn(2, 16, 64)
|
|
25
|
-
out, attn = m(x, x, x)
|
|
26
|
-
print(out.shape)
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Functional API
|
|
30
|
-
```python
|
|
31
|
-
import torch
|
|
32
|
-
import torch.nn.functional as F
|
|
33
|
-
from floyd_net import floyd_scaled_dot_product_attention
|
|
34
|
-
|
|
35
|
-
q = torch.randn(2, 8, 16, 64) # (B, H, L, D)
|
|
36
|
-
k = torch.randn(2, 8, 16, 64)
|
|
37
|
-
v = torch.randn(2, 8, 16, 64)
|
|
38
|
-
out = floyd_scaled_dot_product_attention(q, k, v)
|
|
39
|
-
print(out.shape)
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
## Paper reproductions
|
|
43
|
-
See `paper/` for dataset preparation, configs, and experiment templates to reproduce the results in the paper.
|
|
44
|
-
|
|
45
|
-
## License
|
|
46
|
-
MIT
|
floydnet-0.1.0/paper/README.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# Paper reproductions
|
|
2
|
-
|
|
3
|
-
This folder contains materials to reproduce results from the paper.
|
|
4
|
-
|
|
5
|
-
Structure:
|
|
6
|
-
- `datasets/`: dataset preparation scripts or links
|
|
7
|
-
- `configs/`: YAML/TOML experiment configs
|
|
8
|
-
- `experiments/`: runnable training/eval scripts referencing configs
|
|
9
|
-
- `notebooks/`: exploratory notebooks (optional)
|
|
10
|
-
|
|
11
|
-
Use `uv` to create an environment, then run scripts inside `experiments/`.
|
|
File without changes
|
|
File without changes
|