Skip to content

Commit e0524ca

Browse files
achoumcopybara-github
authored andcommitted
Make TF-DF inspector compatible with non-compressed blob sequence models.
PiperOrigin-RevId: 714949522
1 parent 5d1c23f commit e0524ca

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

tensorflow_decision_forests/component/inspector/blob_sequence.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from __future__ import division
2525
from __future__ import print_function
2626

27-
from typing import Optional, Iterator
27+
from typing import Iterator, Optional
2828

2929
import tensorflow as tf
3030

@@ -56,9 +56,22 @@ def open(self, path: str):
5656
if magic != b"BS":
5757
raise ValueError(f"Invalid blob sequence file {path}")
5858
version = int.from_bytes(self.file_.read(2), byteorder="little")
59-
if version != 0:
60-
raise ValueError(f"Non supported blob sequence version {path}")
61-
reserved = self.file_.read(4)
59+
if version == 0:
60+
reserved = self.file_.read(4)
61+
elif version == 1:
62+
compression = int.from_bytes(self.file_.read(1), byteorder="little")
63+
if compression != 0:
64+
return ValueError(
65+
"The TF-DF inspector does not support this format of model"
66+
" (blob-sequence-v1 with compression). Use the format"
67+
" blob-sequence-v1 without compression instead."
68+
)
69+
reserved = self.file_.read(3)
70+
else:
71+
raise ValueError(
72+
f"Non supported blob sequence version {version} for file {path}. The"
73+
" model was created with a more recent vesion of YDF / TF-DF."
74+
)
6275
del reserved
6376

6477
def close(self):

0 commit comments

Comments
 (0)