---
title: models
---

<div class="python-reference">
<a id="fastvideo.eval.models-functions"></a>
<a id="fastvideo.eval.models"></a>
<p>Model checkpoint resolution and caching for eval metrics.</p>
<p>Single public function — :func:<code>ensure_checkpoint</code> — that hands a metric
a local path to its weights, downloading on miss. Three source kinds:</p>
<ul>
<li>an existing local path → returned as-is;</li>
<li>an HTTP(S) URL → downloaded to <code>get_cache_dir() / name</code> via
  <code>huggingface_hub.http_get</code> (resume + retries built in);</li>
<li>an HF repo id (<code>"org/repo"</code>) → :func:<code>huggingface_hub.hf_hub_download</code>
  if <em>filename</em> is given, else :func:<code>huggingface_hub.snapshot_download</code>.
  <em>name</em> is ignored in HF mode — HF manages its own cache key under
  <code>~/.cache/huggingface/hub</code>.</li>
</ul>
<p>All download paths are filelock-safe (cooperative across threads,
processes, and SLURM ranks) via :func:<code>fastvideo.utils.get_lock</code>.</p>
<h2 id="fastvideo.eval.models.get_lock"><code>fastvideo.eval.models.get_lock</code></h2>
<pre class="doc-signature"><code>get_lock(model_name_or_path: str)</code></pre>

<h2 id="fastvideo.eval.models.get_cache_dir"><code>fastvideo.eval.models.get_cache_dir</code></h2>
<pre class="doc-signature"><code>get_cache_dir() -&gt; Path</code></pre>
<p>Eval cache root.</p>
<p>Layout::</p>
<pre><code>get_cache_dir() / models /   ← URL-fetched checkpoints (LAION head,
                               AMT, GRiT, …)
get_cache_dir() / torch  /   ← redirected ``TORCH_HOME`` (DINO etc.)
get_cache_dir() / clip   /   ← passed as ``download_root`` to
                               ``clip.load(...)`` callsites
~/.cache/huggingface/hub /   ← left at HF's default; widely shared
                               with other ML projects
</code></pre>
<p>Override priority: <code>FASTVIDEO_EVAL_CACHE</code> &gt; <code>$&#123;FASTVIDEO_CACHE_ROOT&#125;/eval</code>.</p>
<p>Metric authors writing new code: when wrapping a third-party loader
that has its own cache convention (CLIP's <code>download_root</code>, pyiqa's
<code>cache_dir</code>, etc.), pass <code>str(get_cache_dir() / "&lt;library&gt;")</code> so
users get a single <code>FASTVIDEO_EVAL_CACHE</code> knob to redirect them all.</p>
<details><summary>Source</summary><pre><code>def get_cache_dir() -&gt; Path:
    &quot;&quot;&quot;Eval cache root.

    Layout::

        get_cache_dir() / models /   ← URL-fetched checkpoints (LAION head,
                                       AMT, GRiT, …)
        get_cache_dir() / torch  /   ← redirected ``TORCH_HOME`` (DINO etc.)
        get_cache_dir() / clip   /   ← passed as ``download_root`` to
                                       ``clip.load(...)`` callsites
        ~/.cache/huggingface/hub /   ← left at HF&#x27;s default; widely shared
                                       with other ML projects

    Override priority: ``FASTVIDEO_EVAL_CACHE`` &gt; ``$&#123;FASTVIDEO_CACHE_ROOT&#125;/eval``.

    Metric authors writing new code: when wrapping a third-party loader
    that has its own cache convention (CLIP&#x27;s ``download_root``, pyiqa&#x27;s
    ``cache_dir``, etc.), pass ``str(get_cache_dir() / &quot;&lt;library&gt;&quot;)`` so
    users get a single ``FASTVIDEO_EVAL_CACHE`` knob to redirect them all.
    &quot;&quot;&quot;
    return Path(envs.FASTVIDEO_EVAL_CACHE.get())</code></pre></details>
<h2 id="fastvideo.eval.models.ensure_checkpoint"><code>fastvideo.eval.models.ensure_checkpoint</code></h2>
<pre class="doc-signature"><code>ensure_checkpoint(name: str, source: str, filename: str | None = None) -&gt; str</code></pre>
<p>Resolve a model checkpoint path, downloading on miss.</p>
<p>See module docstring for the full source contract. <em>name</em> is used
only as the local cache filename for URL sources; ignored otherwise.</p>
<details><summary>Source</summary><pre><code>def ensure_checkpoint(
    name: str,
    source: str,
    filename: str | None = None,
) -&gt; str:
    &quot;&quot;&quot;Resolve a model checkpoint path, downloading on miss.

    See module docstring for the full source contract. *name* is used
    only as the local cache filename for URL sources; ignored otherwise.
    &quot;&quot;&quot;
    if os.path.exists(source):
        return source

    if source.startswith((&quot;http://&quot;, &quot;https://&quot;)):
        return _ensure_url(name, source)

    if &quot;/&quot; in source:
        return _ensure_hf(source, filename)

    raise ValueError(f&quot;Cannot resolve checkpoint: source &#123;source!r&#125; is neither a &quot;
                     &quot;path, URL, nor HF repo id&quot;)</code></pre></details>
</div>
