Spaces:
Running on Zero
Running on Zero
File size: 3,052 Bytes
efa9c6f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import json
import tempfile
import unittest
from pathlib import Path
from grounding_demo.model_spec import MODEL_REPO, MODEL_REVISION
from grounding_demo.native_runtime import inspect_contract, ConfigurationError
class ModelReleaseTests(unittest.TestCase):
def package(self, root):
config = {
"model_type": "groundingpi", "architectures": ["GroundingPIForConditionalGeneration"],
"vision_config": {"model_type": "groundingpi_vision"}, "image_token_id": 151655,
"auto_map": {"AutoModelForImageTextToText": "modeling_groundingpi.GroundingPIForConditionalGeneration",
"AutoProcessor": "processing_groundingpi.GroundingPIProcessor"},
}
for name in ["configuration_groundingpi.py", "configuration_groundingpi_vision.py",
"modeling_groundingpi.py", "modeling_groundingpi_vision.py",
"processing_groundingpi.py", "image_processing_groundingpi.py",
"media_utils.py", "streammind_gate.py", "chat_template.jinja"]:
(root/name).write_text("test fixture")
vocab = {f"<{n}>": n for n in range(1000)}
vocab.update({token: 150000+i for i,token in enumerate(
["<|box_start|>", "<|box_end|>", "<|object_ref_start|>", "<|object_ref_end|>"])})
vocab["<|image_pad|>"] = 151655
for name, data in {"config.json": config, "preprocessor_config.json": {"media_proc_cfg": {}},
"generation_config.json": {"eos_token_id": [151645]},
"tokenizer_config.json": {}, "tokenizer.json": {"model": {"vocab": vocab}}}.items():
(root/name).write_text(json.dumps(data))
return config
def test_release_targets_new_accounts_pinned_public_model(self):
self.assertEqual(MODEL_REPO, "GroundingPI/GroundingPI")
self.assertRegex(MODEL_REVISION, r"^[0-9a-f]{40}$")
def test_new_model_contract_is_accepted_without_executing_model_code(self):
with tempfile.TemporaryDirectory() as d:
root=Path(d);self.package(root)
report=inspect_contract(root,require_weights=False)
self.assertEqual(report["vision"],"groundingpi_vision")
self.assertEqual(report["gam_coordinate_tokens"],1000)
self.assertEqual(report["eos_token_ids"],[151645])
def test_wrong_old_architecture_is_rejected(self):
with tempfile.TemporaryDirectory() as d:
root=Path(d);config=self.package(root)
config["model_type"]="oxygen_vl_v3"
(root/"config.json").write_text(json.dumps(config))
with self.assertRaisesRegex(ConfigurationError,"GroundingPI/GroundingPI"):
inspect_contract(root,require_weights=False)
def test_production_contract_requires_complete_weights(self):
with tempfile.TemporaryDirectory() as d:
root=Path(d);self.package(root)
with self.assertRaisesRegex(ConfigurationError,"weight shards"):
inspect_contract(root)
|