lesiondiffusion-mlx 0.2.6.post2__tar.gz → 0.2.8__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.
Files changed (23) hide show
  1. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/PKG-INFO +38 -30
  2. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/README.md +35 -27
  3. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/pyproject.toml +8 -6
  4. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/__init__.py +1 -1
  5. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/_schedules.py +3 -3
  6. lesiondiffusion_mlx-0.2.8/src/lesiondiffusion_mlx/_typing.py +129 -0
  7. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/medmlx.py +219 -133
  8. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/mlx_model.py +77 -2
  9. lesiondiffusion_mlx-0.2.6.post2/src/lesiondiffusion_mlx/_typing.py +0 -111
  10. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/.gitignore +0 -0
  11. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/LICENSE +0 -0
  12. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/THIRD_PARTY_NOTICES.md +0 -0
  13. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/_arrays.py +0 -0
  14. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/_attention.py +0 -0
  15. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/_nax_conv.py +0 -0
  16. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/_nifti.py +0 -0
  17. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/_reference.py +0 -0
  18. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/_source_half.py +0 -0
  19. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/_spatial.py +0 -0
  20. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/mlx_pipeline.py +0 -0
  21. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/mlx_sampling.py +0 -0
  22. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/py.typed +0 -0
  23. {lesiondiffusion_mlx-0.2.6.post2 → lesiondiffusion_mlx-0.2.8}/src/lesiondiffusion_mlx/reference.json +0 -0
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lesiondiffusion-mlx
3
- Version: 0.2.6.post2
3
+ Version: 0.2.8
4
4
  Summary: Add synthetic lesions to CT with native MLX, with controls for organ, size, placement and phenotype
5
5
  Project-URL: Homepage, https://medmlx.org
6
- Project-URL: Documentation, https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.6.post2/README.md
6
+ Project-URL: Documentation, https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.8/README.md
7
7
  Project-URL: Repository, https://github.com/MedMLX/lesiondiffusion-mlx
8
8
  Project-URL: Issues, https://github.com/MedMLX/lesiondiffusion-mlx/issues
9
9
  Project-URL: Weights, https://huggingface.co/MedMLX/lesiondiffusion-mlx
@@ -24,7 +24,7 @@ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
24
24
  Classifier: Topic :: Scientific/Engineering :: Image Processing
25
25
  Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
26
26
  Requires-Python: <3.14,>=3.13
27
- Requires-Dist: medmlx-core==0.2.6
27
+ Requires-Dist: medmlx-core<0.3,>=0.2.6
28
28
  Requires-Dist: mlx==0.32.4; platform_system == 'Darwin' and platform_machine == 'arm64'
29
29
  Requires-Dist: nibabel<6,>=5.3
30
30
  Requires-Dist: numpy<3,>=2.2
@@ -54,14 +54,14 @@ Add synthetic lesions to CT with native MLX, with controls for organ, size, plac
54
54
 
55
55
  [![PyPI](https://img.shields.io/pypi/v/lesiondiffusion-mlx)](https://pypi.org/project/lesiondiffusion-mlx/)
56
56
  [![Python](https://img.shields.io/pypi/pyversions/lesiondiffusion-mlx)](https://pypi.org/project/lesiondiffusion-mlx/)
57
- [![License](https://img.shields.io/badge/License-Apache_2.0-blue)](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.6.post2/LICENSE)
57
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue)](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.8/LICENSE)
58
58
  [![Apple Silicon](https://img.shields.io/badge/Apple_Silicon-MLX-black?logo=apple)](https://github.com/ml-explore/mlx)
59
59
  [![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97_Hugging_Face-weights-yellow)](https://huggingface.co/MedMLX/lesiondiffusion-mlx)
60
60
  [![MedMLX](https://img.shields.io/badge/MedMLX-runtime-A51C30)](https://github.com/MedMLX/medmlx)
61
61
 
62
62
  [Model weights](https://huggingface.co/MedMLX/lesiondiffusion-mlx) · [MedMLX](https://github.com/MedMLX/medmlx)
63
63
 
64
- <img src="https://raw.githubusercontent.com/MedMLX/lesiondiffusion-mlx/v0.2.6.post2/docs/showcase.png" alt="CT with a synthetic lesion placed inside an organ mask" width="100%">
64
+ <img src="https://raw.githubusercontent.com/MedMLX/lesiondiffusion-mlx/v0.2.8/docs/showcase.png" alt="CT with a synthetic lesion placed inside an organ mask" width="100%">
65
65
 
66
66
  </div>
67
67
 
@@ -69,16 +69,17 @@ Add synthetic lesions to CT with native MLX, with controls for organ, size, plac
69
69
  | :--- | :--- |
70
70
  | **Input** | CT + aligned binary organ mask |
71
71
  | **Output** | Synthetic CT and lesion mask |
72
- | **Hardware** | Apple Silicon with Metal; **18.74 GB** peak MLX memory for `lesiondiffusion` in source mode on a 160×160×128, 1 mm RAS crop. |
72
+ | **Hardware** | Apple Silicon with Metal; **5.19 GB** peak MLX memory for `lesiondiffusion` in the default conditioned mode and **3.46 GB** in source mode on a 160×160×128, 1 mm RAS crop. |
73
73
 
74
- The v0.2.5 memory measurement used the AMOS case 0008 crop and 200 diffusion steps with
75
- `inference_mode="source"`: FP32 LMNet and text encoder, FP16 LINet and VQ.
76
- It does not measure the default conditioned mode or larger volumes. Peak MLX
77
- memory excludes host preprocessing and other applications.
74
+ Both measurements used an AMOS case 0008 crop and 200 diffusion steps: FP32 LMNet and
75
+ text encoders, FP16 LINet and VQ encoder, and an FP32 VQ decoder in conditioned mode
76
+ (FP16 in source mode). `output_region="lesion"` decodes twice in sequence without
77
+ raising the peak. They do not measure larger volumes. Peak MLX memory excludes host
78
+ preprocessing and other applications.
78
79
 
79
80
  ## Use with MedMLX
80
81
 
81
- The [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) is the lowest-friction way to use this model. It installs this runtime, downloads its weights on first use, and lets an AI agent describe, check and run `lesiondiffusion` for you.
82
+ Use the [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) to run `lesiondiffusion` from an MCP client. Weights download on first use.
82
83
 
83
84
  ```sh
84
85
  uv tool install --python 3.13 "medmlx[generate,mcp]"
@@ -96,7 +97,7 @@ For Codex, use `codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-wor
96
97
  ```bash
97
98
  uv venv --python 3.13
98
99
  source .venv/bin/activate
99
- uv pip install "lesiondiffusion-mlx>=0.2.6.post2"
100
+ uv pip install "lesiondiffusion-mlx>=0.2.8"
100
101
  ```
101
102
 
102
103
  ## Run
@@ -116,12 +117,9 @@ result = run(
116
117
  print(result["outputs"]["synthetic_image"])
117
118
  ```
118
119
 
119
- Omitting `weights_path` downloads `MedMLX/lesiondiffusion-mlx` into the shared MedMLX
120
- cache on first use; interrupted downloads resume and later runs work offline. With
121
- MedMLX installed, `medmlx setup lesiondiffusion` downloads it ahead of time. To use your
120
+ Weights download from `MedMLX/lesiondiffusion-mlx` on first use. Use `medmlx setup lesiondiffusion` to download ahead of time. To use your
122
121
  own copy, pass a folder containing `model.safetensors` and `tokenizer.json` as
123
- `weights_path`. Conversion receipts are not required. `details.weights_revision` records
124
- the downloaded commit, or `null` for a folder without a MedMLX download record.
122
+ `weights_path`. Conversion receipts are not required.
125
123
 
126
124
  ### Inputs and outputs
127
125
 
@@ -139,7 +137,7 @@ the downloaded commit, or `null` for a folder without a MedMLX download record.
139
137
  | `bbox_center_voxel` | Optional `[I, J, K]` box center on the standardized grid; placement is automatic otherwise |
140
138
  | `diffusion_steps`, `seed` | Sampling controls; the upstream defaults are 200 and 23 |
141
139
  | `inference_mode` | `"conditioned"` (default) or `"source"`; see below |
142
- | `output_region` | `"full"` (default) or `"box"` |
140
+ | `output_region` | `"full"` (default), `"box"` or `"lesion"`; see below |
143
141
  | `weights_path` | Optional folder containing `model.safetensors` and `tokenizer.json` |
144
142
  | `overwrite` | `False` by default; existing outputs are never replaced |
145
143
 
@@ -159,24 +157,34 @@ the box or organ.
159
157
 
160
158
  The outputs are `synthetic_ct.nii.gz` (float32 HU), `lesion_mask.nii.gz` and
161
159
  `organ_mask.nii.gz` (uint8) on the standardized grid. The decoder reconstructs the
162
- whole CT, so voxels outside the lesion can change. `output_region="box"` keeps the
163
- generated CT only over the lesion box, feathers it into the input over 6 mm and also
164
- writes the full reconstruction as `raw_synthetic_ct.nii.gz`. `run` returns
165
- `{"outputs": {...}, "details": {...}}` with the generation settings, quality checks,
166
- stage timing and weights revision. Invalid inputs raise `InvalidInputError`; missing
160
+ whole CT, and that reconstruction does not reproduce the input exactly: away from the
161
+ lesion it shifts attenuation by several HU, by an amount that depends on the volume.
162
+ `output_region` controls how much of it reaches `synthetic_ct.nii.gz`:
163
+
164
+ - `"full"` writes the reconstruction as upstream does, so every voxel can change.
165
+ - `"box"` keeps the reconstruction over the lesion box and feathers it into the input
166
+ over 6 mm. Tissue inside the box keeps the shift.
167
+ - `"lesion"` also decodes the unchanged input and adds only the difference between
168
+ the two decodes to the input CT, within 33 voxels of the lesion along each axis.
169
+ The shift cancels, and voxels farther away are the input unchanged. Use it when
170
+ the surrounding anatomy should keep its measured values.
171
+
172
+ `"box"` and `"lesion"` also write the full reconstruction as `raw_synthetic_ct.nii.gz`.
173
+ `run` returns `{"outputs": {...}, "details": {...}}`, with run metadata in `details`.
174
+ Invalid inputs raise `InvalidInputError`; missing
167
175
  or mismatched weights raise `AssetNotReadyError`. Synthetic output is not ground truth.
168
176
 
169
177
  ### Inference modes
170
178
 
171
179
  `"conditioned"`, the default, enables the inpainting network's trained text context,
172
180
  which the pinned upstream configuration turns off, and runs FP16 convolution, fused
173
- attention and compiled denoisers natively. `"source"` follows the upstream inference
174
- configuration and arithmetic for reproduction; its results can differ from
175
- conditioned output. MLX and Torch random streams differ, so a seed repeats results
176
- only within MLX. Inference needs Apple Silicon with Metal and has no CPU fallback.
181
+ attention and compiled denoisers natively. It decodes in FP32, because the decoder's
182
+ activations can exceed the FP16 range on some volumes. `"source"` follows the
183
+ upstream inference configuration and arithmetic for reproduction, including FP16
184
+ decoding; when that overflows, the run raises an error instead of writing a CT. Its
185
+ results can differ from conditioned output. MLX and Torch random streams differ, so a seed repeats results
186
+ only within MLX. Inference requires Apple Silicon with Metal.
177
187
 
178
188
  ## License
179
189
 
180
- [Apache-2.0](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.6.post2/LICENSE). See [third-party notices](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.6.post2/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
181
-
182
- For research and education. Outputs require human review.
190
+ [Apache-2.0](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.8/LICENSE). See [third-party notices](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.8/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
@@ -6,14 +6,14 @@ Add synthetic lesions to CT with native MLX, with controls for organ, size, plac
6
6
 
7
7
  [![PyPI](https://img.shields.io/pypi/v/lesiondiffusion-mlx)](https://pypi.org/project/lesiondiffusion-mlx/)
8
8
  [![Python](https://img.shields.io/pypi/pyversions/lesiondiffusion-mlx)](https://pypi.org/project/lesiondiffusion-mlx/)
9
- [![License](https://img.shields.io/badge/License-Apache_2.0-blue)](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.6.post2/LICENSE)
9
+ [![License](https://img.shields.io/badge/License-Apache_2.0-blue)](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.8/LICENSE)
10
10
  [![Apple Silicon](https://img.shields.io/badge/Apple_Silicon-MLX-black?logo=apple)](https://github.com/ml-explore/mlx)
11
11
  [![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97_Hugging_Face-weights-yellow)](https://huggingface.co/MedMLX/lesiondiffusion-mlx)
12
12
  [![MedMLX](https://img.shields.io/badge/MedMLX-runtime-A51C30)](https://github.com/MedMLX/medmlx)
13
13
 
14
14
  [Model weights](https://huggingface.co/MedMLX/lesiondiffusion-mlx) · [MedMLX](https://github.com/MedMLX/medmlx)
15
15
 
16
- <img src="https://raw.githubusercontent.com/MedMLX/lesiondiffusion-mlx/v0.2.6.post2/docs/showcase.png" alt="CT with a synthetic lesion placed inside an organ mask" width="100%">
16
+ <img src="https://raw.githubusercontent.com/MedMLX/lesiondiffusion-mlx/v0.2.8/docs/showcase.png" alt="CT with a synthetic lesion placed inside an organ mask" width="100%">
17
17
 
18
18
  </div>
19
19
 
@@ -21,16 +21,17 @@ Add synthetic lesions to CT with native MLX, with controls for organ, size, plac
21
21
  | :--- | :--- |
22
22
  | **Input** | CT + aligned binary organ mask |
23
23
  | **Output** | Synthetic CT and lesion mask |
24
- | **Hardware** | Apple Silicon with Metal; **18.74 GB** peak MLX memory for `lesiondiffusion` in source mode on a 160×160×128, 1 mm RAS crop. |
24
+ | **Hardware** | Apple Silicon with Metal; **5.19 GB** peak MLX memory for `lesiondiffusion` in the default conditioned mode and **3.46 GB** in source mode on a 160×160×128, 1 mm RAS crop. |
25
25
 
26
- The v0.2.5 memory measurement used the AMOS case 0008 crop and 200 diffusion steps with
27
- `inference_mode="source"`: FP32 LMNet and text encoder, FP16 LINet and VQ.
28
- It does not measure the default conditioned mode or larger volumes. Peak MLX
29
- memory excludes host preprocessing and other applications.
26
+ Both measurements used an AMOS case 0008 crop and 200 diffusion steps: FP32 LMNet and
27
+ text encoders, FP16 LINet and VQ encoder, and an FP32 VQ decoder in conditioned mode
28
+ (FP16 in source mode). `output_region="lesion"` decodes twice in sequence without
29
+ raising the peak. They do not measure larger volumes. Peak MLX memory excludes host
30
+ preprocessing and other applications.
30
31
 
31
32
  ## Use with MedMLX
32
33
 
33
- The [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) is the lowest-friction way to use this model. It installs this runtime, downloads its weights on first use, and lets an AI agent describe, check and run `lesiondiffusion` for you.
34
+ Use the [MedMLX MCP server](https://github.com/MedMLX/medmlx/blob/main/docs/mcp.md) to run `lesiondiffusion` from an MCP client. Weights download on first use.
34
35
 
35
36
  ```sh
36
37
  uv tool install --python 3.13 "medmlx[generate,mcp]"
@@ -48,7 +49,7 @@ For Codex, use `codex mcp add medmlx -- "$MEDMLX" serve --root "$HOME/medmlx-wor
48
49
  ```bash
49
50
  uv venv --python 3.13
50
51
  source .venv/bin/activate
51
- uv pip install "lesiondiffusion-mlx>=0.2.6.post2"
52
+ uv pip install "lesiondiffusion-mlx>=0.2.8"
52
53
  ```
53
54
 
54
55
  ## Run
@@ -68,12 +69,9 @@ result = run(
68
69
  print(result["outputs"]["synthetic_image"])
69
70
  ```
70
71
 
71
- Omitting `weights_path` downloads `MedMLX/lesiondiffusion-mlx` into the shared MedMLX
72
- cache on first use; interrupted downloads resume and later runs work offline. With
73
- MedMLX installed, `medmlx setup lesiondiffusion` downloads it ahead of time. To use your
72
+ Weights download from `MedMLX/lesiondiffusion-mlx` on first use. Use `medmlx setup lesiondiffusion` to download ahead of time. To use your
74
73
  own copy, pass a folder containing `model.safetensors` and `tokenizer.json` as
75
- `weights_path`. Conversion receipts are not required. `details.weights_revision` records
76
- the downloaded commit, or `null` for a folder without a MedMLX download record.
74
+ `weights_path`. Conversion receipts are not required.
77
75
 
78
76
  ### Inputs and outputs
79
77
 
@@ -91,7 +89,7 @@ the downloaded commit, or `null` for a folder without a MedMLX download record.
91
89
  | `bbox_center_voxel` | Optional `[I, J, K]` box center on the standardized grid; placement is automatic otherwise |
92
90
  | `diffusion_steps`, `seed` | Sampling controls; the upstream defaults are 200 and 23 |
93
91
  | `inference_mode` | `"conditioned"` (default) or `"source"`; see below |
94
- | `output_region` | `"full"` (default) or `"box"` |
92
+ | `output_region` | `"full"` (default), `"box"` or `"lesion"`; see below |
95
93
  | `weights_path` | Optional folder containing `model.safetensors` and `tokenizer.json` |
96
94
  | `overwrite` | `False` by default; existing outputs are never replaced |
97
95
 
@@ -111,24 +109,34 @@ the box or organ.
111
109
 
112
110
  The outputs are `synthetic_ct.nii.gz` (float32 HU), `lesion_mask.nii.gz` and
113
111
  `organ_mask.nii.gz` (uint8) on the standardized grid. The decoder reconstructs the
114
- whole CT, so voxels outside the lesion can change. `output_region="box"` keeps the
115
- generated CT only over the lesion box, feathers it into the input over 6 mm and also
116
- writes the full reconstruction as `raw_synthetic_ct.nii.gz`. `run` returns
117
- `{"outputs": {...}, "details": {...}}` with the generation settings, quality checks,
118
- stage timing and weights revision. Invalid inputs raise `InvalidInputError`; missing
112
+ whole CT, and that reconstruction does not reproduce the input exactly: away from the
113
+ lesion it shifts attenuation by several HU, by an amount that depends on the volume.
114
+ `output_region` controls how much of it reaches `synthetic_ct.nii.gz`:
115
+
116
+ - `"full"` writes the reconstruction as upstream does, so every voxel can change.
117
+ - `"box"` keeps the reconstruction over the lesion box and feathers it into the input
118
+ over 6 mm. Tissue inside the box keeps the shift.
119
+ - `"lesion"` also decodes the unchanged input and adds only the difference between
120
+ the two decodes to the input CT, within 33 voxels of the lesion along each axis.
121
+ The shift cancels, and voxels farther away are the input unchanged. Use it when
122
+ the surrounding anatomy should keep its measured values.
123
+
124
+ `"box"` and `"lesion"` also write the full reconstruction as `raw_synthetic_ct.nii.gz`.
125
+ `run` returns `{"outputs": {...}, "details": {...}}`, with run metadata in `details`.
126
+ Invalid inputs raise `InvalidInputError`; missing
119
127
  or mismatched weights raise `AssetNotReadyError`. Synthetic output is not ground truth.
120
128
 
121
129
  ### Inference modes
122
130
 
123
131
  `"conditioned"`, the default, enables the inpainting network's trained text context,
124
132
  which the pinned upstream configuration turns off, and runs FP16 convolution, fused
125
- attention and compiled denoisers natively. `"source"` follows the upstream inference
126
- configuration and arithmetic for reproduction; its results can differ from
127
- conditioned output. MLX and Torch random streams differ, so a seed repeats results
128
- only within MLX. Inference needs Apple Silicon with Metal and has no CPU fallback.
133
+ attention and compiled denoisers natively. It decodes in FP32, because the decoder's
134
+ activations can exceed the FP16 range on some volumes. `"source"` follows the
135
+ upstream inference configuration and arithmetic for reproduction, including FP16
136
+ decoding; when that overflows, the run raises an error instead of writing a CT. Its
137
+ results can differ from conditioned output. MLX and Torch random streams differ, so a seed repeats results
138
+ only within MLX. Inference requires Apple Silicon with Metal.
129
139
 
130
140
  ## License
131
141
 
132
- [Apache-2.0](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.6.post2/LICENSE). See [third-party notices](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.6.post2/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
133
-
134
- For research and education. Outputs require human review.
142
+ [Apache-2.0](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.8/LICENSE). See [third-party notices](https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.8/THIRD_PARTY_NOTICES.md). Model weights retain their publisher terms.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "lesiondiffusion-mlx"
7
- version = "0.2.6.post2"
7
+ version = "0.2.8"
8
8
  description = "Add synthetic lesions to CT with native MLX, with controls for organ, size, placement and phenotype"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.13,<3.14"
@@ -37,7 +37,7 @@ authors = [
37
37
  { name = "Alfredo Sandoval Jr." },
38
38
  ]
39
39
  dependencies = [
40
- "medmlx-core==0.2.6",
40
+ "medmlx-core>=0.2.6,<0.3",
41
41
  "mlx==0.32.4; platform_system == 'Darwin' and platform_machine == 'arm64'",
42
42
  "nibabel>=5.3,<6",
43
43
  "numpy>=2.2,<3",
@@ -48,7 +48,7 @@ dependencies = [
48
48
 
49
49
  [project.urls]
50
50
  Homepage = "https://medmlx.org"
51
- Documentation = "https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.6.post2/README.md"
51
+ Documentation = "https://github.com/MedMLX/lesiondiffusion-mlx/blob/v0.2.8/README.md"
52
52
  Repository = "https://github.com/MedMLX/lesiondiffusion-mlx"
53
53
  Issues = "https://github.com/MedMLX/lesiondiffusion-mlx/issues"
54
54
  Weights = "https://huggingface.co/MedMLX/lesiondiffusion-mlx"
@@ -94,10 +94,10 @@ extend-select = ["TID251", "TID252"]
94
94
  select = ["E", "F", "I", "UP", "B", "SIM", "RUF"]
95
95
 
96
96
  [tool.pyright]
97
- include = ["scripts","src","tests","typings"]
98
- extraPaths = ["src", "scripts"]
97
+ include = ["src", "tests", "typings"]
98
+ extraPaths = ["src"]
99
99
  pythonVersion = "3.13"
100
- typeCheckingMode = "standard"
100
+ typeCheckingMode = "strict"
101
101
  enableTypeIgnoreComments = false
102
102
  reportUnnecessaryTypeIgnoreComment = "error"
103
103
 
@@ -105,6 +105,8 @@ reportUnnecessaryTypeIgnoreComment = "error"
105
105
  ban-relative-imports = "all"
106
106
 
107
107
  [tool.ruff.lint.flake8-tidy-imports.banned-api]
108
+ "typing.Any" = {msg = "Use a precise type and parse untyped values at the boundary."}
109
+ "typing_extensions.Any" = {msg = "Use a precise type and parse untyped values at the boundary."}
108
110
 
109
111
  [tool.hatch.build.targets.sdist]
110
112
  only-include = [
@@ -32,7 +32,7 @@ if TYPE_CHECKING:
32
32
  )
33
33
  from lesiondiffusion_mlx.mlx_sampling import DdimSampler as DdimSampler
34
34
 
35
- __version__ = "0.2.6.post2"
35
+ __version__ = "0.2.8"
36
36
 
37
37
  __all__ = [
38
38
  "LINET_CONFIG",
@@ -3,7 +3,7 @@
3
3
  from __future__ import annotations
4
4
 
5
5
 
6
- def _is_runtime_integer(value: object) -> bool:
6
+ def is_integer(value: object) -> bool:
7
7
  """Recognize integer inputs while excluding booleans."""
8
8
  return isinstance(value, int) and not isinstance(value, bool)
9
9
 
@@ -26,9 +26,9 @@ def lesion_diffusion_timesteps(steps: int, total: int = 1000) -> tuple[int, ...]
26
26
  ``total < steps``, or the last index would reach ``total`` (for example
27
27
  ``steps=3`` or ``steps=1000`` with ``total=1000``).
28
28
  """
29
- if not _is_runtime_integer(steps) or steps < 1:
29
+ if not is_integer(steps) or steps < 1:
30
30
  raise ValueError("LesionDiffusion DDIM steps must be a positive integer")
31
- if not _is_runtime_integer(total) or total < steps:
31
+ if not is_integer(total) or total < steps:
32
32
  raise ValueError("LesionDiffusion DDIM schedule must contain at least as many timesteps")
33
33
  timesteps = tuple(value + 1 for value in range(0, total, total // steps))
34
34
  if timesteps[-1] >= total:
@@ -0,0 +1,129 @@
1
+ """Native array and dependency contracts used by the source implementation."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import TYPE_CHECKING, Protocol
6
+
7
+ from lesiondiffusion_mlx._arrays import HostArray as HostArray
8
+
9
+ if TYPE_CHECKING:
10
+ from collections.abc import Sequence
11
+ from typing import Literal, overload
12
+
13
+ import mlx.core as mx
14
+ from medmlx_core.typing import FastRuntime as CoreFastRuntime
15
+ from medmlx_core.typing import MlxRuntime as CoreMlxRuntime
16
+ from tokenizers import Encoding
17
+
18
+ type Array = mx.array
19
+ type Dtype = mx.Dtype
20
+ type ArrayValue = bool | int | float | complex | list[ArrayValue] | tuple[ArrayValue, ...]
21
+
22
+ class TokenizerContract(Protocol):
23
+ def enable_truncation(self, max_length: int) -> None:
24
+ """Enable tokenizer truncation at the requested length."""
25
+ ...
26
+ def enable_padding(self, *, length: int, pad_id: int, pad_token: str) -> None:
27
+ """Configure tokenizer padding and its token ID."""
28
+ ...
29
+ def encode_batch(self, inputs: Sequence[str]) -> list[Encoding]:
30
+ """Encode a batch of input strings."""
31
+ ...
32
+
33
+ class MetalKernel(Protocol):
34
+ def __call__(
35
+ self,
36
+ *,
37
+ inputs: Sequence[Array],
38
+ template: Sequence[tuple[str, int | bool | Dtype]],
39
+ grid: tuple[int, int, int],
40
+ threadgroup: tuple[int, int, int],
41
+ output_shapes: Sequence[Sequence[int]],
42
+ output_dtypes: Sequence[Dtype],
43
+ ) -> list[Array]:
44
+ """Launch a Metal kernel and return its output arrays."""
45
+ ...
46
+
47
+ class Fast(CoreFastRuntime, Protocol):
48
+ """The part of ``mx.fast`` used here, with typed Metal-kernel construction."""
49
+
50
+ scaled_dot_product_attention = staticmethod(mx.fast.scaled_dot_product_attention)
51
+
52
+ def metal_kernel(
53
+ self,
54
+ name: str,
55
+ input_names: Sequence[str],
56
+ output_names: Sequence[str],
57
+ source: str,
58
+ header: str = "",
59
+ ensure_row_contiguous: bool = True,
60
+ atomic_outputs: bool = False,
61
+ compile_options: object | None = None,
62
+ ) -> MetalKernel:
63
+ """Compile a named Metal kernel with the supplied source."""
64
+ ...
65
+
66
+ class Random(Protocol):
67
+ normal = staticmethod(mx.random.normal)
68
+ seed = staticmethod(mx.random.seed)
69
+
70
+ class Mlx(CoreMlxRuntime, Protocol):
71
+ """Native ``mlx.core`` operations injected into the model and pipeline."""
72
+
73
+ @property
74
+ def fast(self) -> Fast:
75
+ """Return native fast operations and Metal-kernel construction."""
76
+ ...
77
+
78
+ @property
79
+ def random(self) -> Random:
80
+ """Return native random generation operations."""
81
+ ...
82
+
83
+ @overload
84
+ def load(
85
+ self,
86
+ file: str,
87
+ /,
88
+ format: Literal["safetensors"],
89
+ return_metadata: Literal[False] = False,
90
+ ) -> dict[str, Array]:
91
+ """Load a safetensors file as a name-to-array mapping."""
92
+ ...
93
+
94
+ @overload
95
+ def load(
96
+ self, file: str, /, format: str | None = None, return_metadata: bool = False
97
+ ) -> Array | dict[str, Array] | tuple[dict[str, Array], dict[str, object]]:
98
+ """Load arrays, and optionally metadata, from a supported file format."""
99
+ ...
100
+
101
+ addmm = staticmethod(mx.addmm)
102
+ all = staticmethod(mx.all)
103
+ argmin = staticmethod(mx.argmin)
104
+ clear_cache = staticmethod(mx.clear_cache)
105
+ compile = staticmethod(mx.compile)
106
+ contiguous = staticmethod(mx.contiguous)
107
+ cos = staticmethod(mx.cos)
108
+ device_info = staticmethod(mx.device_info)
109
+ erf = staticmethod(mx.erf)
110
+ exp = staticmethod(mx.exp)
111
+ full = staticmethod(mx.full)
112
+ isfinite = staticmethod(mx.isfinite)
113
+ reciprocal = staticmethod(mx.reciprocal)
114
+ sin = staticmethod(mx.sin)
115
+ softmax = staticmethod(mx.softmax)
116
+ sqrt = staticmethod(mx.sqrt)
117
+ sum = staticmethod(mx.sum)
118
+
119
+
120
+ # Defined at runtime because callers pass it to ``typing.cast`` unquoted.
121
+ class ArrayConstructor(Protocol):
122
+ def __call__(
123
+ self,
124
+ value: HostArray | Array | ArrayValue,
125
+ /,
126
+ dtype: Dtype | None = None,
127
+ ) -> Array:
128
+ """Construct a native array from values and an optional dtype."""
129
+ ...