Files
tokenspeed/test/runtime/test_model_config_remote_code.py

69 lines
2.6 KiB
Python

# Copyright (c) 2026 LightSeek Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import os
import sys
from transformers import LlamaConfig
# CI Registration (parsed via AST, runtime no-op)
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from ci_system.ci_register import register_cuda_ci # noqa: E402
register_cuda_ci(est_time=5, suite="runtime-1gpu")
from tokenspeed.runtime.configs.model_config import ModelConfig # noqa: E402
from tokenspeed.runtime.utils.server_args import ServerArgs # noqa: E402
def test_model_config_remote_code_requires_opt_in(tmp_path):
LlamaConfig(
architectures=["LlamaForCausalLM"],
auto_map={"AutoConfig": "configuration_custom.CustomConfig"},
vocab_size=128,
hidden_size=64,
intermediate_size=128,
num_hidden_layers=2,
num_attention_heads=4,
num_key_value_heads=2,
max_position_embeddings=256,
).save_pretrained(tmp_path)
(tmp_path / "configuration_custom.py").write_text(
"from transformers import LlamaConfig\n"
"\n"
"class CustomConfig(LlamaConfig):\n"
" def __init__(self, **kwargs):\n"
" super().__init__(**kwargs)\n"
" self.vocab_size = 256\n"
)
model_path = str(tmp_path)
args = ServerArgs(model=model_path, device="cpu")
default = ModelConfig(model_path, model_override_args="{}", server_args=args)
trusted = ModelConfig(
model_path,
trust_remote_code=True,
model_override_args="{}",
server_args=args,
)
assert default.vocab_size == 128
assert trusted.vocab_size == 256