Skip to content

AirLLM 2.8T LLM inference with single 4GB GPU

fix(lora): accept UTF-8 BOM in dataset files

agammannc64a9079d40c
diff --git a/air_llm/airllm/lora_data.py b/air_llm/airllm/lora_data.py
index ebafa72..ed1bc68 100644
--- a/air_llm/airllm/lora_data.py
+++ b/air_llm/airllm/lora_data.py
@@ -83,7 +83,7 @@ def load_records(path) -> list:
if not p.is_file():
raise FileNotFoundError(p)
suffix = p.suffix.lower()
- text = p.read_text(encoding="utf-8")
+ text = p.read_text(encoding="utf-8-sig")
records = []
if suffix == ".txt":
blocks = [b.strip() for b in text.split("\n\n") if b.strip()]
diff --git a/air_llm/tests/test_lora_data.py b/air_llm/tests/test_lora_data.py
index 6414e60..d7a722b 100644
--- a/air_llm/tests/test_lora_data.py
+++ b/air_llm/tests/test_lora_data.py
@@ -74,6 +74,18 @@ class TestLoadRecords(unittest.TestCase):
recs = load_records(path)
self.assertEqual([r["text"] for r in recs], ["x", "y"])
+ def test_utf8_bom_dataset(self):
+ with tempfile.TemporaryDirectory() as tmp:
+ for suffix, data in (
+ (".json", json.dumps([{"text": "hello"}])),
+ (".jsonl", json.dumps({"text": "hello"}) + "\n"),
+ (".txt", "hello"),
+ ):
+ path = Path(tmp) / f"data{suffix}"
+ path.write_bytes(b"\xef\xbb\xbf" + data.encode("utf-8"))
+ with self.subTest(suffix=suffix):
+ self.assertEqual(load_records(path)[0]["text"], "hello")
+
class TestIterTrainItems(unittest.TestCase):
def test_epochs_and_step_cap(self):