Skip to content

DataOperationsCatalog.Cache: reading a vector column while the cache is still filling can throw ArgumentOutOfRangeException ("valuesCount") from CacheDataView.ColumnCache.ImplVec.Fetch (Microsoft.ML 5.0.1, arm64) #7884

Open

Description

@birdnamoo

Summary

A cursor that reads a vector column of mlContext.Data.Cache(view) straight after the call, while the cache is still being filled, intermittently throws

System.ArgumentOutOfRangeException: If specified, must be non-negative. (Parameter 'valuesCount')
   at Microsoft.ML.Data.CacheDataView.ColumnCache.ImplVec`1.Fetch(Int32 idx, VBuffer`1& value)

The rows are fine — the same scan succeeds in other runs on the same data — so a row is read before it is completely written.

Reproduction

Microsoft.ML 5.0.1, .NET 10.0.402, macOS arm64. A text file of 4,000,000 rows, a,b,c,d,y with four random floats and a class number:

var ml = new MLContext(1);
var loader = ml.Data.CreateTextLoader(new TextLoader.Options
{
    HasHeader = true, Separators = [','],
    Columns = [new TextLoader.Column("Features", DataKind.Single, 0, 3), new TextLoader.Column("Label", DataKind.Single, 4)],
});
var cached = ml.Data.Cache(loader.Load(path));
var column = cached.Schema["Features"];
using var cursor = cached.GetRowCursor([column]);
var get = cursor.GetGetter<VBuffer<float>>(column);
VBuffer<float> value = default;
while (cursor.MoveNext()) get(ref value);   // intermittently throws in Fetch

Each run builds a fresh MLContext, loader and cache. Measured: more than a quarter of 20 runs threw. With an in-memory source (LoadFromEnumerable, 3,000,000 rows) the rate is lower (about 1 run in 30), so it depends on the reader having to wait for the filler.

What avoids it

A cursor over all columns that reads no value, run to its end before the real scan (using var c = cached.GetRowCursor(cached.Schema); while (c.MoveNext()) { }), gave 0 failures in 20 runs on the text file. A cursor over no columns did not help (7 in 80 failures on the enumerable source), and neither did a cursor reading only the scalar label.

Notes

Not verified on x64: the failure may depend on the weaker memory ordering of arm64 (the reader seeing the row count before the row's offsets). A consumer that trains on tables of millions of rows meets it as a training run dying at the start of its search about half the time.

Workaround in the consumer: cache through a helper that fills the copy (the all-column no-read pass above) before returning it.

Activity

  1. added
    area-Core
    on Nov 9, 2026
  2. added
    untriaged
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Coreuntriaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions