Skip to content

Commit

Permalink
Patch/llama index and device (#155)
Browse files Browse the repository at this point in the history
* fix: llamaindex imports

* fix: rare device mismatch

* chore: use only ruff linting

* ruff

* ruff

* isort
  • Loading branch information
bclavie authored Feb 23, 2024
1 parent 3855b83 commit c5c759c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"outputs": [],
"source": [
"import instructor\n",
"# If you're using llamaindex 0.10 or above, these need to be imported from llama_index.core instead!\n",
"from llama_index import Document\n",
"from llama_index.text_splitter import SentenceSplitter\n",
"from openai import OpenAI\n",
Expand Down Expand Up @@ -459,7 +460,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.13"
"version": "3.11.7"
}
},
"nbformat": 4,
Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,4 @@ unfixable = [
"T201",
"T203",
]
ignore-init-module-imports = true

[tool.ruff.lint.isort]
section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
ignore-init-module-imports = true
8 changes: 6 additions & 2 deletions ragatouille/data/preprocessors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
from llama_index import Document
from llama_index.text_splitter import SentenceSplitter
try:
from llama_index import Document
from llama_index.text_splitter import SentenceSplitter
except ImportError:
from llama_index.core import Document
from llama_index.core.text_splitter import SentenceSplitter


def llama_index_sentence_splitter(
Expand Down
8 changes: 4 additions & 4 deletions ragatouille/models/colbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ def add_to_index(
bsize=bsize,
)
else:
if self.config.index_bsize != bsize: # Update bsize if it's different
self.config.index_bsize = bsize
if self.config.index_bsize != bsize: # Update bsize if it's different
self.config.index_bsize = bsize

updater = IndexUpdater(
config=self.config, searcher=searcher, checkpoint=self.checkpoint
Expand Down Expand Up @@ -757,7 +757,7 @@ def encode(
- encodings.shape[1],
encodings.shape[2],
)
),
).to(device=encodings.device),
],
dim=1,
)
Expand All @@ -771,7 +771,7 @@ def encode(
- doc_masks.shape[1],
),
-float("inf"),
),
).to(device=encodings.device),
],
dim=1,
)
Expand Down

0 comments on commit c5c759c

Please sign in to comment.