"""Create a config-only derivative backed by hard-linked text-only weights."""
import json,os,pathlib,sys
src=pathlib.Path(sys.argv[1]); dst=pathlib.Path(sys.argv[2])
assert src.is_dir() and (src/'model.safetensors.index.json').is_file()
dst.mkdir(parents=True,exist_ok=False)
for entry in src.iterdir():
    if entry.is_file() and entry.name!='config.json':os.link(entry,dst/entry.name)
full=json.loads((src/'config.json').read_text()); text=full['text_config'].copy()
text.update(architectures=['Qwen3_5ForCausalLM'],model_type='qwen3_5_text',dtype=full.get('dtype','bfloat16'),tie_word_embeddings=full.get('tie_word_embeddings',False))
if 'quantization_config' in full:
    text['quantization_config']=json.loads(json.dumps(full['quantization_config']).replace('model.language_model.','model.'))
(dst/'config.json').write_text(json.dumps(text,indent=2)+'\n')
(dst/'DERIVATION.json').write_text(json.dumps({'source':str(src),'weight_modifications':'none; hard-linked unchanged nonvisual tensors','config':'text_config flattened; architecture causal; quant module ignores remapped'},indent=2))
print(dst)
