Spaces:
Running on Zero
Running on Zero
Download tests/test_model_release.py from FanLR/GroundingPI: direct link, hf CLI and curl.
- Browser
- Download file 3.05 kB
-
https://huggingface.co/spaces/FanLR/GroundingPI/resolve/main/tests/test_model_release.py
- Command line
-
hf download hf://spaces/FanLR/GroundingPI/tests/test_model_release.py
-
curl -L -o test_model_release.py https://huggingface.co/spaces/FanLR/GroundingPI/resolve/main/tests/test_model_release.py
3.05 kB
| 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) | |