Skip to content

MachineLearning.GetTrainedModelsStats always throws a deserialization exception #8271

Closed
@svalbuena

Description

@svalbuena

Elastic.Clients.Elasticsearch version: 8.14.6

Elasticsearch version: 8.14.3

.NET runtime version: 8.0

Operating system version: Windows

Description of the problem including expected versus actual behavior:
I'm using the MachineLearning.GetTrainedModelsStatsAsync call to get the stats of a trained model, this request always results in System.Text.Json.JsonException: The JSON value could not be converted to System.Int32. Path: $.trained_model_stats[0].model_size_stats.required_native_memory_bytes. Invoking the route manually http://localhost:9200/_ml/trained_models/intfloat__e5-small-v2/_stats works.
Upon inspection of the Model class the response is deserialized into, I found the required_native_memory_bytes is defined as an int rather than ByteSize as the other fields of the same type:

namespace Elastic.Clients.Elasticsearch.MachineLearning;

public sealed partial class TrainedModelSizeStats
{
	/// <summary>
	/// <para>The size of the model in bytes.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("model_size_bytes")]
	public Elastic.Clients.Elasticsearch.ByteSize ModelSizeBytes { get; init; }

	/// <summary>
	/// <para>The amount of memory required to load the model in bytes.</para>
	/// </summary>
	[JsonInclude, JsonPropertyName("required_native_memory_bytes")]
	public int RequiredNativeMemoryBytes { get; init; }
}

The required_native_memory_bytes is much bigger than an int.

Steps to reproduce:

  1. Deploy an ML model
  2. Use the .NET elastic client to invoke the model like await client.MachineLearning.GetTrainedModelsStatsAsync(new Ids("intfloat__e5-small-v2"), cancellationToken);
  3. The code throws a deserialization exception

Expected behavior
The TrainedModelSizeStats class should type the RequiredNativeMemoryBytes field as Elastic.Clients.Elasticsearch.ByteSize, and the GetTrainedModelsStatsAsync call should succeed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions