Run this model with HF Jobs

Run tiny-random/mistral-multimodal-embed 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/tiny-random/mistral-multimodal-embed. 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/tiny-random/mistral-multimodal-embed 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.
File size: 2,844 Bytes
3bad2ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def create_model(source_model_id: str, source_revision: str, save_folder: str) -> str:
    import json
    from pathlib import Path

    import torch
    from huggingface_hub import hf_hub_download
    from transformers import AutoConfig, AutoModel

    folder = Path(save_folder)
    folder.mkdir(parents=True, exist_ok=True)
    for name in (
        "configuration_mistral_contrastive.py",
        "modeling_mistral_contrastive.py",
        "image_processing_mistral_contrastive.py",
        "image_transforms.py",
        "preprocessor_config.json",
        "tokenizer.json",
        "tokenizer_config.json",
        "special_tokens_map.json",
        "LICENSE",
    ):
        (folder / name).write_bytes(Path(hf_hub_download(source_model_id, name, revision=source_revision)).read_bytes())

    config = json.loads(Path(hf_hub_download(source_model_id, "config.json", revision=source_revision)).read_text())
    # 64-wide residual streams keep the 131,072-row embedding near 17 MB while
    # preserving heads*head_dim == width in both towers and the 4-layer,
    # 64-wide temporal encoder.
    config.update(
        text_dim=64,
        text_num_hidden_layers=4,
        text_num_attention_heads=2,
        text_head_dim=32,
        text_intermediate_size=256,
        vision_dim=64,
        vision_num_hidden_layers=4,
        vision_num_attention_heads=2,
        vision_head_dim=32,
        vision_intermediate_size=256,
        temporal_num_attention_heads=2,
    )
    (folder / "config.json").write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8")

    model_config = AutoConfig.from_pretrained(folder, trust_remote_code=True)
    torch.manual_seed(42)
    torch.set_default_dtype(torch.bfloat16)
    model = AutoModel.from_config(model_config, trust_remote_code=True)
    torch.set_default_dtype(torch.float32)
    # Deterministic, active weights; keep the FP32 logit scale at its source value.
    with torch.no_grad():
        for name, parameter in sorted(model.named_parameters()):
            if name == "logit_scale" or parameter.ndim == 0:
                continue
            if name.endswith(".bias"):
                parameter.zero_()
            elif name.endswith("weight") and "norm" in name:
                parameter.fill_(1.0)
            else:
                parameter.normal_(0.0, 0.02)
    model.save_pretrained(folder, safe_serialization=True)
    # save_pretrained rewrites config.json; restore the shrunk source document.
    (folder / "config.json").write_text(json.dumps(config, indent=2) + "\n", encoding="utf-8")
    print(model)
    return str(model)


if __name__ == "__main__":
    create_model(
        source_model_id="mistralai/Mistral-Multimodal-Embed-1B",
        source_revision="38fe0971eb3944a1273f429338a9cf704f223bff",
        save_folder="/tmp/mistral-multimodal-embed",
    )