Repository navigation
refactor library #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
geospatial-jeff
wants to merge
45
commits into
main
Choose a base branch
from
refactor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
refactor library #382
Changes from 14 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
64313d9
first pass at refactor with claude
geospatial-jeff 3add2dc
add ci workflow
geospatial-jeff 9e9ae08
imports top of file
geospatial-jeff f2556cf
simplify __init__
geospatial-jeff 39979a5
add matryoshka flag
geospatial-jeff 5c7ae6a
rename factory to embedding, rename backbone to layers, move finetune…
geospatial-jeff 36781af
dont lint notebooks
geospatial-jeff d624e67
move ClayDataModule to train, add finetune extra
geospatial-jeff 897ec55
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c4f6e85
move ClayDataModule to train, add finetune extra
geospatial-jeff 998a800
Merge branch 'refactor' of https://github.com/Clay-foundation/model i…
geospatial-jeff eef6ee5
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 57688ca
improve unit test coverage
geospatial-jeff b2676bf
build/test with hatch
geospatial-jeff 9983897
Potential fix for pull request finding 'CodeQL / Workflow does not co…
geospatial-jeff 00e6f09
add type hints
geospatial-jeff b5107ef
add pyarrow dep
geospatial-jeff 364f69a
Merge branch 'refactor' of https://github.com/Clay-foundation/model i…
geospatial-jeff 1f2af1f
remove top level utils
geospatial-jeff bfc9aae
remove dead code, fix doc paths, fix datamodule predict, remove print…
geospatial-jeff 4c3047a
pass custom config file
geospatial-jeff 014931c
add pydantic model for config.yaml
geospatial-jeff 4b5dfd5
add pydantic model for config.yaml
geospatial-jeff 1b125b4
cleanup stale environment setup, define config in one place
geospatial-jeff 968d66f
add mypy
geospatial-jeff 609bf1d
separate training logic from model forward pass
geospatial-jeff df51f94
add integration tests
geospatial-jeff b38cb6c
test py3.13
geospatial-jeff 3eb69c1
build: adopt uv ruff and ty tooling (#383)
isaaccorley 5ff069c
correct learning rate in docs to match code, confirmed through commit…
geospatial-jeff e86e80e
remove duplicate variable
geospatial-jeff fbd40b1
skip sklearn in test without train extra
geospatial-jeff f267669
remove optional dependencies like geopandas/rasterio, will add this b…
geospatial-jeff 4cbb4e6
clean up docs a bit
geospatial-jeff b773a71
fix relative metadata path when installed as package
geospatial-jeff 4b6bb0e
remove RegressionEncoder and SegmentEncoder, these were legitimately …
geospatial-jeff 3e63bf3
remove elle, we'll bring it back later. bunch of other small cleanups
geospatial-jeff 4145511
cleanup more comments, a few lines of dead code
geospatial-jeff f1789d2
cleanup more comments, a few lines of dead code
geospatial-jeff 1ec422e
move configure_training_defaults to train
geospatial-jeff 798d5b6
add Datacube typedict for static type checking, validate datacube bef…
geospatial-jeff fa67083
BREAKING move teacher to train to avoid downloading teacher on inference
geospatial-jeff dd7dea2
remove factory functions from public api
geospatial-jeff 0926539
add s2 inference pipeline
geospatial-jeff 5a5e8a1
clean up inference pipeline
geospatial-jeff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: [main] | ||
| pull_request: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| lint: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: "3.11" | ||
| - run: pip install ruff | ||
| - run: ruff check . --exclude "*.ipynb" | ||
| - run: ruff format --check . --exclude "*.ipynb" | ||
|
|
||
| test: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| python-version: ["3.11", "3.12"] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-python@v5 | ||
| with: | ||
| python-version: ${{ matrix.python-version }} | ||
| - run: pip install hatch | ||
| - run: hatch run test | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| # Contributing to Clay Foundation Model | ||
|
|
||
| Thank you for your interest in contributing to Clay! This guide covers how to set up a development environment, run tests, and submit changes. | ||
|
|
||
| ## Development Setup | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Python 3.11 or later | ||
| - Git | ||
| - (Optional) CUDA-capable GPU for model training/inference | ||
|
|
||
| ### Installation | ||
|
|
||
| ```bash | ||
| # Clone the repository | ||
| git clone https://github.com/Clay-foundation/model.git | ||
| cd model | ||
|
|
||
| # Install in development mode with all extras | ||
| pip install -e ".[dev]" | ||
|
|
||
| # Or using mamba for a full environment | ||
| mamba env create --file environment.yml | ||
| mamba activate claymodel | ||
| pip install -e ".[dev]" | ||
| ``` | ||
|
|
||
| ### Verify Installation | ||
|
|
||
| ```bash | ||
| # Run the test suite | ||
| pytest tests/ -v | ||
|
|
||
| # Check linting | ||
| ruff check claymodel/ tests/ | ||
|
|
||
| # Check formatting | ||
| ruff format --check claymodel/ tests/ | ||
| ``` | ||
|
|
||
| ## Project Structure | ||
|
|
||
| ``` | ||
| claymodel/ | ||
| __init__.py # Package exports (lazy imports) | ||
| api.py # High-level API: embed(), load_model(), normalize() | ||
| cli.py # CLI commands: clay embed, clay info, clay benchmark | ||
| model.py # Core model: Encoder, Decoder, ClayMAE, factory functions | ||
| module.py # Lightning module: ClayMAEModule | ||
| utils.py # Utilities: position embeddings, weight loading | ||
| datamodule.py # Training data loading | ||
| configs/ | ||
| metadata.yaml # Bundled sensor metadata (wavelengths, normalization stats) | ||
| inference/ | ||
| deterministic.py # DeterministicInference context manager | ||
| elle.py # ELLE quality scoring probe | ||
| masking.py # PatchAnalyzer for chip quality filtering | ||
| finetune/ # Downstream task examples | ||
| tests/ # Test suite | ||
| docs/ # Documentation (Jupyter Book) | ||
| configs/ # Training configs | ||
| ``` | ||
|
|
||
| ## Running Tests | ||
|
|
||
| ```bash | ||
| # Run all tests | ||
| pytest tests/ -v | ||
|
|
||
| # Run a specific test file | ||
| pytest tests/test_model.py -v | ||
|
|
||
| # Run with coverage | ||
| pytest tests/ --cov=claymodel --cov-report=term-missing | ||
| ``` | ||
|
|
||
| Tests use a tiny encoder (dim=192, random weights) so they run in seconds without a GPU or checkpoint. | ||
|
|
||
| ## Code Style | ||
|
|
||
| We use [ruff](https://docs.astral.sh/ruff/) for linting and formatting. | ||
|
|
||
| ```bash | ||
| # Check for lint errors | ||
| ruff check claymodel/ tests/ | ||
|
|
||
| # Auto-fix fixable errors | ||
| ruff check claymodel/ tests/ --fix | ||
|
|
||
| # Check formatting | ||
| ruff format --check claymodel/ tests/ | ||
|
|
||
| # Auto-format | ||
| ruff format claymodel/ tests/ | ||
| ``` | ||
|
|
||
| Configuration is in `ruff.toml`. Key rules: | ||
| - Max line length: 88 (ruff default) | ||
| - Max function arguments: 6 (with exceptions for model constructors) | ||
| - Import sorting enforced (isort-compatible) | ||
|
|
||
| ## Making Changes | ||
|
|
||
| ### Before You Start | ||
|
|
||
| 1. Check [existing issues](https://github.com/Clay-foundation/model/issues) for related work | ||
| 2. For significant changes, open an issue first to discuss the approach | ||
|
|
||
| ### Workflow | ||
|
|
||
| 1. Create a branch from `main` | ||
| 2. Make your changes | ||
| 3. Run `ruff check` and `ruff format` | ||
| 4. Run `pytest tests/` | ||
| 5. Submit a pull request | ||
|
|
||
| ### Key Principles | ||
|
|
||
| - **No changes to model computation**: Clay v1.5 must produce identical embeddings. Any refactoring must be verified with before/after numerical comparison. | ||
| - **Test new functionality**: Add tests for new features. Tests should be fast (<30s total). | ||
| - **Follow existing patterns**: Look at how similar features are implemented before adding new ones. | ||
| - **Sensor metadata in metadata.yaml**: When adding new sensor support, add entries to both `configs/metadata.yaml` and `claymodel/configs/metadata.yaml`. | ||
|
|
||
| ## Adding New Sensors | ||
|
|
||
| To add support for a new satellite sensor: | ||
|
|
||
| 1. Compute normalization statistics (mean/std per band) from a representative sample | ||
| 2. Find the central wavelength of each band in micrometers | ||
| 3. Add an entry to `configs/metadata.yaml` and `claymodel/configs/metadata.yaml` | ||
| 4. Test with `clay info --sensor your-sensor` and `normalize(pixels, "your-sensor")` | ||
| 5. Submit a PR with the metadata and a brief description of the instrument | ||
|
|
||
| ## Questions? | ||
|
|
||
| - Open an [issue](https://github.com/Clay-foundation/model/issues) | ||
| - Start a [discussion](https://github.com/Clay-foundation/model/discussions) | ||
| - Email: hello@madewithclay.org |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.