Skip to content

torch inference for segmentation#4

Open
alisterburt wants to merge 4 commits intomgflast:masterfrom
alisterburt:torch-inference
Open

torch inference for segmentation#4
alisterburt wants to merge 4 commits intomgflast:masterfrom
alisterburt:torch-inference

Conversation

@alisterburt
Copy link

this PR is on top of #3 and adds

  • a torch implementation of the segmentation model
  • some utilities for converting weights
  • some code to validate that implementations match numerically

This was heavily LLM assisted, generally okay but had to work around some differences in padding behavior between TF and torch

Not really expecting this to be merged directly, is just good to know it's possible to run inference using your weights in torch

============================================================
PyTorch vs TensorFlow Model Equivalence Validation
============================================================

============================================================
WEIGHT VALIDATION
============================================================
TensorFlow parameters:
  Trainable: 128,897,505
  Total: 128,917,537

PyTorch parameters:
  Trainable: 128,897,505
  Total: 128,897,505

✓ PASS: Parameter counts match

============================================================
MULTIPLE INPUT VALIDATION (5 tests)
============================================================

Test 1/5:

============================================================
FORWARD PASS VALIDATION
============================================================
Test input shape (TF format): (64, 64, 64, 1)
TensorFlow output shape: (1, 64, 64, 64, 1)
TensorFlow output range: [0.000000, 0.999970]
PyTorch output shape: (1, 64, 64, 64, 1)
PyTorch output range: [0.000000, 0.999970]

Numerical Differences:
  Max absolute difference:  2.35e-06
  Mean absolute difference: 7.40e-08
  Max relative difference:  1.28e-05
  Mean relative difference: 9.34e-07

✓ PASS: Outputs match within tolerance (rtol=0.0001, atol=1e-05)

Test 2/5:

============================================================
FORWARD PASS VALIDATION
============================================================
Test input shape (TF format): (128, 128, 128, 1)
TensorFlow output shape: (1, 128, 128, 128, 1)
TensorFlow output range: [0.000000, 0.999988]
PyTorch output shape: (1, 128, 128, 128, 1)
PyTorch output range: [0.000000, 0.999988]

Numerical Differences:
  Max absolute difference:  2.32e-06
  Mean absolute difference: 3.67e-08
  Max relative difference:  1.72e-05
  Mean relative difference: 1.07e-06

✓ PASS: Outputs match within tolerance (rtol=0.0001, atol=1e-05)

Test 3/5:

============================================================
FORWARD PASS VALIDATION
============================================================
Test input shape (TF format): (64, 64, 64, 1)
TensorFlow output shape: (1, 64, 64, 64, 1)
TensorFlow output range: [0.000000, 0.999902]
PyTorch output shape: (1, 64, 64, 64, 1)
PyTorch output range: [0.000000, 0.999902]

Numerical Differences:
  Max absolute difference:  1.52e-06
  Mean absolute difference: 7.58e-08
  Max relative difference:  1.43e-05
  Mean relative difference: 9.38e-07

✓ PASS: Outputs match within tolerance (rtol=0.0001, atol=1e-05)

Test 4/5:

============================================================
FORWARD PASS VALIDATION
============================================================
Test input shape (TF format): (128, 128, 128, 1)
TensorFlow output shape: (1, 128, 128, 128, 1)
TensorFlow output range: [0.000000, 0.999987]
PyTorch output shape: (1, 128, 128, 128, 1)
PyTorch output range: [0.000000, 0.999987]

Numerical Differences:
  Max absolute difference:  2.74e-06
  Mean absolute difference: 3.74e-08
  Max relative difference:  1.70e-05
  Mean relative difference: 1.09e-06

✓ PASS: Outputs match within tolerance (rtol=0.0001, atol=1e-05)

Test 5/5:

============================================================
FORWARD PASS VALIDATION
============================================================
Test input shape (TF format): (64, 64, 64, 1)
TensorFlow output shape: (1, 64, 64, 64, 1)
TensorFlow output range: [0.000000, 0.999940]
PyTorch output shape: (1, 64, 64, 64, 1)
PyTorch output range: [0.000000, 0.999940]

Numerical Differences:
  Max absolute difference:  2.62e-06
  Mean absolute difference: 7.60e-08
  Max relative difference:  2.57e-05
  Mean relative difference: 1.06e-06

✓ PASS: Outputs match within tolerance (rtol=0.0001, atol=1e-05)

✓ ALL TESTS PASSED (5/5)

============================================================
VALIDATION SUMMARY
============================================================
Weight validation:  ✓ PASSED
Forward pass tests: ✓ PASSED

🎉 ALL VALIDATIONS PASSED!

- Restructure package to use src/easymode/ layout
- Replace setup.py with modern pyproject.toml
- Add hatchling build backend with hatch-vcs versioning
- Add comprehensive CI/CD via GitHub Actions
- Add pre-commit hooks (ruff, mypy, validate-pyproject)
- Add pytest testing infrastructure
- Preserve GPL v3 license and all functionality
- Version: v0.0.2 (managed via git tags)

BREAKING CHANGES:
- Minimum Python version now 3.10 (previously implicit 3.7+)
- Package structure changed to src-layout (import paths unchanged)
@alisterburt
Copy link
Author

ooft - diff is ugly, code changes from #3 are in src/easymode/segmentation/torch_version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments