Run this model with HF Jobs
Run ModernVBERT/colmodernvbert-base on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/ModernVBERT/colmodernvbert-base. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/ModernVBERT/colmodernvbert-base on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use ModernVBERT/colmodernvbert-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ColPali
How to use ModernVBERT/colmodernvbert-base with ColPali:
# No code snippets available yet for this library. # To use this model, check the repository files and the library's documentation. # Want to help? PRs adding snippets are welcome at: # https://github.com/huggingface/huggingface.js
- Notebooks
- Google Colab
- Kaggle
Add legacy colmodernvbert-base conversion script
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119from __future__ import annotations
import argparseimport jsonimport shutilfrom pathlib import Path
import torchfrom safetensors.torch import load_file, save_file
TEXT_EMBED_KEY = "model.text_model.embeddings.tok_embeddings.weight"TEXT_EXTRA_EMBED_KEY = "model.text_model.embeddings.tok_embeddings.additional_embedding.weight"CONNECTOR_IN = "model.connector.modality_projection.proj.weight"CONNECTOR_OUT = "model.connector.modality_projection.weight"VISION_PREFIX_IN = "model.vision_model."VISION_PREFIX_OUT = "model.vision_model.vision_model."
def parse_args() -> argparse.Namespace: parser = argparse.ArgumentParser( description="Convert a legacy ModernVBERT/colmodernvbert-base checkpoint into engine format." ) parser.add_argument("input_dir", type=Path, help="Legacy base model directory") parser.add_argument("output_dir", type=Path, help="Converted base model directory") parser.add_argument( "--config-template", type=Path, default=Path(__file__).resolve().with_name("config.json"), help="Engine-style config.json template to copy into the converted output", ) return parser.parse_args()
def ensure_new_dir(path: Path) -> None: if path.exists(): raise FileExistsError(f"{path} already exists; refusing to overwrite it") path.mkdir(parents=True)
def copy_support_files(src: Path, dst: Path) -> None: excluded = {"model.safetensors", "config.json", "BUILD_INFO.json"} for item in src.iterdir(): if item.name in excluded: continue target = dst / item.name if item.is_dir(): shutil.copytree(item, target) else: shutil.copy2(item, target)
def convert_base_weights(src_dir: Path, dst_dir: Path) -> dict[str, int]: src_weights = load_file(str(src_dir / "model.safetensors")) out_weights = {} merged_embeddings = 0 renamed_connector = 0 renamed_vision = 0
for key, value in src_weights.items(): if key == TEXT_EXTRA_EMBED_KEY: continue if key == TEXT_EMBED_KEY and TEXT_EXTRA_EMBED_KEY in src_weights: value = torch.cat([value, src_weights[TEXT_EXTRA_EMBED_KEY]], dim=0) merged_embeddings += 1 if key == CONNECTOR_IN: key = CONNECTOR_OUT renamed_connector += 1 elif key.startswith(VISION_PREFIX_IN) and not key.startswith(VISION_PREFIX_OUT): key = VISION_PREFIX_OUT + key[len(VISION_PREFIX_IN) :] renamed_vision += 1 out_weights[key] = value
save_file(out_weights, str(dst_dir / "model.safetensors")) return { "source_tensor_count": len(src_weights), "output_tensor_count": len(out_weights), "merged_token_embedding_tables": merged_embeddings, "renamed_connector_tensors": renamed_connector, "renamed_vision_tensors": renamed_vision, }
def write_config(template_path: Path, dst_dir: Path) -> dict[str, str]: if not template_path.exists(): raise FileNotFoundError(f"Config template not found: {template_path}") config = json.loads(template_path.read_text()) (dst_dir / "config.json").write_text(json.dumps(config, indent=2) + "\n") return {"config_template": str(template_path)}
def main() -> None: args = parse_args() ensure_new_dir(args.output_dir) copy_support_files(args.input_dir, args.output_dir)
weight_info = convert_base_weights(args.input_dir, args.output_dir) config_info = write_config(args.config_template, args.output_dir)
build_info = { "description": "Legacy colmodernvbert-base converted to engine-style base layout.", "input_dir": str(args.input_dir), "output_dir": str(args.output_dir), **weight_info, **config_info, "key_mapping": { TEXT_EXTRA_EMBED_KEY: f"merged into {TEXT_EMBED_KEY}", CONNECTOR_IN: CONNECTOR_OUT, VISION_PREFIX_IN: VISION_PREFIX_OUT, }, } (args.output_dir / "BUILD_INFO.json").write_text(json.dumps(build_info, indent=2) + "\n")
print(f"Wrote {args.output_dir}") print(f"Converted {weight_info['output_tensor_count']} base tensors")
if __name__ == "__main__": main()convert_legacy_colmvb_base.pyAdded+119