Skip to content

Commit d2e27d9

Browse files
[Minor] Bump into a new serialization version. (#425)
Since #419 modifies the serialization method, it is necessary to bump into a new serialization version. Signed-off-by: Yuchuan <[email protected]>
1 parent 8755129 commit d2e27d9

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

cpp/support/json_serializer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class SerializeVersion {
6262
* \brief The current serialization version. When the serialization result of any object in
6363
* XGrammar is changed, this version should be bumped.
6464
*/
65-
static constexpr const char kXGrammarSerializeVersion[] = "v5";
65+
static constexpr const char kXGrammarSerializeVersion[] = "v6";
6666
};
6767

6868
/*!

tests/python/test_serialization.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def construct_compiled_grammar():
4242

4343
def test_get_serialization_version():
4444
"""Test the version of the serialized JSON string."""
45-
assert xgr.get_serialization_version() == "v5"
45+
assert xgr.get_serialization_version() == "v6"
4646

4747

4848
def test_serialize_grammar():
@@ -61,7 +61,7 @@ def test_serialize_grammar():
6161
"complete_fsm": None,
6262
"per_rule_fsms": [],
6363
"allow_empty_rule_ids": [],
64-
"__VERSION__": "v5",
64+
"__VERSION__": "v6",
6565
}
6666
# The fsms are the same one, but the start state and end states are different.
6767
assert json.loads(serialized) == expected_json
@@ -81,14 +81,14 @@ def test_serialize_grammar_exception():
8181
"allow_empty_rule_ids": [],
8282
"complete_fsm": None,
8383
"per_rule_fsms": [],
84-
"__VERSION__": "v5",
84+
"__VERSION__": "v6",
8585
}
8686

8787
expected_json["__VERSION__"] = "v1" # Change version to trigger error
8888
with pytest.raises(xgr.DeserializeVersionError):
8989
xgr.Grammar.deserialize_json(json.dumps(expected_json))
9090

91-
expected_json["__VERSION__"] = "v5"
91+
expected_json["__VERSION__"] = "v6"
9292
expected_json.pop("rules") # Remove required field to trigger error
9393
with pytest.raises(xgr.DeserializeFormatError):
9494
xgr.Grammar.deserialize_json(json.dumps(expected_json))
@@ -140,7 +140,7 @@ def test_serialize_tokenizer_info():
140140
'"decoded_vocab":["1","212","a","A","b","\\u00e4\\u00b8\\u0080","-","aBc","abc"],'
141141
'"sorted_decoded_vocab":[[6,"-"],[3,"A"],[2,"a"],[7,"aBc"],[8,"abc"],[4,"b"],[5,"\\u00e4\\u00b8\\u0080"]],'
142142
'"trie_subtree_nodes_range":[1,2,5,4,5,6,7],'
143-
'"__VERSION__":"v5"}'
143+
'"__VERSION__":"v6"}'
144144
)
145145
assert json.loads(serialized) == json.loads(expected_json)
146146

@@ -221,7 +221,7 @@ def test_serialize_compiled_grammar():
221221
"add_prefix_space": True,
222222
"stop_token_ids": [0, 1],
223223
},
224-
"__VERSION__": "v5",
224+
"__VERSION__": "v6",
225225
}
226226

227227
class AdaptiveTokenMask(BaseModel):

0 commit comments

Comments
 (0)