Skip to content

Commit 570b013

Browse files
Various typing fixes (#320)
Co-authored-by: Jérémy Chaverot <jeremy.chaverot@epfl.ch>
1 parent 6931183 commit 570b013

20 files changed

Lines changed: 127 additions & 81 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"include": ["../../src/mmore/colvision", "../../src/mmore/tui"],
3+
"exclude": ["../../build", "../../dist", "**/__pycache__", "*.egg-info"],
4+
"executionEnvironments": [
5+
{
6+
"root": "../../src/mmore/colvision",
7+
"extraPaths": ["../../src"]
8+
},
9+
{
10+
"root": "../../src/mmore/tui",
11+
"extraPaths": ["../../src"]
12+
}
13+
],
14+
"pythonVersion": "3.11",
15+
"typeCheckingMode": "standard"
16+
}

.github/workflows/pyright.yml

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,29 @@ on:
88

99
jobs:
1010
pyright:
11+
name: "Pyright"
1112
runs-on: ubuntu-latest
1213
steps:
1314
- uses: actions/checkout@v6
1415

15-
- name: Set up Python 3.12
16+
- name: Set up Python 3.11
1617
uses: actions/setup-python@v6
1718
with:
18-
python-version: "3.12"
19+
python-version: "3.11"
1920

20-
- name: Install uv and create venv
21-
run: |
22-
pipx install uv
23-
uv venv .venv
21+
- name: Install uv
22+
run: pipx install uv
2423

25-
- name: Install dependencies
26-
run: |
27-
source .venv/bin/activate
28-
uv pip install -e ".[process,index,rag,api,cpu,dev,websearch]"
24+
- name: Install base dependencies
25+
run: uv venv .venv && source .venv/bin/activate && uv pip install -e ".[process,index,rag,api,tui,cpu,dev,websearch]"
2926

30-
- name: Run Pyright
27+
- name: Run Pyright (base)
3128
continue-on-error: true
32-
run: |
33-
source .venv/bin/activate
34-
pyright
29+
run: source .venv/bin/activate && pyright --project pyrightconfig.json
3530

36-
- name: Install dependencies - colvision
37-
run: |
38-
uv venv .venv-colvision
39-
source .venv-colvision/bin/activate
40-
uv pip install -e ".[colvision,cpu,dev]"
31+
- name: Install colvision dependencies
32+
run: uv venv .venv-colvision && source .venv-colvision/bin/activate && uv pip install -e ".[colvision,tui,cpu,dev]"
4133

42-
- name: Run Pyright - colvision
34+
- name: Run Pyright (colvision)
4335
continue-on-error: true
44-
run: |
45-
source .venv-colvision/bin/activate
46-
pyright src/mmore/colvision
36+
run: source .venv-colvision/bin/activate && pyright --project .github/pyright/pyrightconfig.colvision.json

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ MultimodalSample.to_jsonl(out_file, result_pdf)
160160

161161
To launch the MMORE pipeline, follow the specialised instructions in the docs.
162162

163-
![The MMORE pipelines architecture](https://github.com/user-attachments/assets/0cd61466-1680-43ed-9d55-7bd483a04a09)
163+
![The MMORE pipelines architecture](docs/source/doc_images/pipeline_mmore+.png)
164164

165165

166166
1. **:page_facing_up: Input Documents**

docs/source/advanced_usage/profiler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ If you only need to measure execution time (wall clock), use `time_function` or
119119
```python
120120
from mmore.profiler import time_function, time_context
121121

122-
@time_function
122+
@time_function()
123123
def quick_check():
124124
pass
125125

501 KB
Loading

pyrightconfig.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"include": ["src/mmore", "tests"],
3+
"exclude": [
4+
"build",
5+
"dist",
6+
"**/__pycache__",
7+
"*.egg-info",
8+
"src/mmore/colvision"
9+
],
10+
"executionEnvironments": [
11+
{
12+
"root": "src/mmore",
13+
"extraPaths": ["src"]
14+
},
15+
{
16+
"root": "tests",
17+
"extraPaths": ["src"]
18+
}
19+
],
20+
"pythonVersion": "3.11",
21+
"typeCheckingMode": "standard"
22+
}

src/mmore/colvision/model_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ def resolve_model_classes(model_name: str) -> Tuple[Type, Type]:
5757
Raises:
5858
ValueError: if the model name does not match any known pattern.
5959
"""
60-
import colpali_engine.models as models_module
60+
try:
61+
import colpali_engine.models as models_module
62+
except ImportError as e:
63+
raise ImportError(
64+
"colpali_engine is required for ColVision. Install with: pip install mmore[colvision]"
65+
) from e
6166

6267
name_lower = model_name.lower()
6368

src/mmore/colvision/retriever.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def embed_queries(texts: List[str], model, processor) -> List[np.ndarray]:
5959
with torch.no_grad():
6060
batch_query = {k: v.to(model.device) for k, v in batch_query.items()}
6161
emb = model(**batch_query)
62-
vectors.extend(list(torch.unbind(emb.to("cpu"))))
62+
vectors.extend(list(emb.to("cpu").unbind()))
6363
return [v.float().numpy() for v in vectors]
6464

6565

src/mmore/process/post_processor/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,15 @@ def load_postprocessor(config: BasePostProcessorConfig) -> BasePostProcessor:
3333
from .translator import TranslatorConfig, TranslatorPostProcessor
3434

3535
config_translator = load_config(config.args, TranslatorConfig)
36-
return TranslatorPostProcessor.from_config(config_translator)
36+
return cast(
37+
BasePostProcessor, TranslatorPostProcessor.from_config(config_translator)
38+
)
3739

3840
elif config.type == "metafuse":
3941
from .metafuse import MetaDataInfusor, MetaDataInfusorConfig
4042

4143
config_metafuse = load_config(config.args, MetaDataInfusorConfig)
42-
return MetaDataInfusor.from_config(config_metafuse)
44+
return cast(BasePostProcessor, MetaDataInfusor.from_config(config_metafuse))
4345

4446
else:
4547
raise ValueError(f"Unrecognized postprocessor type: {config.type}")

src/mmore/process/processors/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,13 @@ def __getstate__(self):
216216
del state["_pool"]
217217
return state
218218

219-
def __setstate__(self, state):
219+
def __setstate__(self, state: Dict[str, Any]):
220220
"""
221221
Called when the object is unpickled (received by the worker).
222222
We restore the state and set _pool to None (workers don't need the pool manager).
223223
"""
224-
self.__dict__.update(state)
224+
for key, value in state.items():
225+
setattr(self, key, value)
225226
# Initialize _pool as None in the worker process
226227
self._pool = None
227228
# Workers should never own the pool

0 commit comments

Comments
 (0)