Llm/LlmPaths.cs

Static helper class that defines constant file paths for a local LLM model and its reference tensors, tokenizer, and metadata. It also provides a ReferenceStage method that validates a filename and returns a combined path under the model root.

namespace LlmPoc.Llm;

public static class LlmPaths
{
	public const string RuntimeModelResource = "models/tinystories.llmmdl";
	public const string Root = "models/tinystories-instruct-1m";
	public const string Model = Root + "/model.bin";
	public const string Config = Root + "/config.json";
	public const string Manifest = Root + "/tensor_manifest.json";
	public const string Reference = Root + "/reference.json";
	public const string ReferenceLogits = Root + "/reference_logits.f32";
	public const string ReferenceIntermediates = Root + "/reference_intermediates.json";
	public const string ReferenceEmbedding = Root + "/reference_embedding.f32";
	public const string ReferenceLayer0Ln1 = Root + "/reference_layer0_ln1.f32";
	public const string ReferenceLayer0Q = Root + "/reference_layer0_q.f32";
	public const string ReferenceLayer0K = Root + "/reference_layer0_k.f32";
	public const string ReferenceLayer0V = Root + "/reference_layer0_v.f32";
	public const string ReferenceLayer0QHeads = Root + "/reference_layer0_q_heads.f32";
	public const string ReferenceLayer0KHeads = Root + "/reference_layer0_k_heads.f32";
	public const string ReferenceLayer0VHeads = Root + "/reference_layer0_v_heads.f32";
	public const string ReferenceLayer0ScoresScaledUnmasked =
		Root + "/reference_layer0_scores_scaled_unmasked.f32";
	public const string ReferenceLayer0AttentionMask =
		Root + "/reference_layer0_attention_mask.json";
	public const string ReferenceLayer0ScoresMaskedPreSoftmax =
		Root + "/reference_layer0_scores_masked_pre_softmax.f32";
	public const string ReferenceLayer0AttentionProbs =
		Root + "/reference_layer0_attention_probs.f32";
	public const string ReferenceLayer0AttentionContextHeads =
		Root + "/reference_layer0_attention_context_heads.f32";
	public const string ReferenceLayer0AttentionMerged =
		Root + "/reference_layer0_attention_merged.f32";
	public const string ReferenceLayer0AttentionOutProj =
		Root + "/reference_layer0_attention_out_proj.f32";
	public const string ReferenceLayer0AttentionResidual =
		Root + "/reference_layer0_attention_residual.f32";
	public const string ReferenceLayer0Ln2 = Root + "/reference_layer0_ln2.f32";
	public const string ReferenceLayer0MlpFc = Root + "/reference_layer0_mlp_fc.f32";
	public const string ReferenceLayer0MlpGelu = Root + "/reference_layer0_mlp_gelu.f32";
	public const string ReferenceLayer0MlpProj = Root + "/reference_layer0_mlp_proj.f32";
	public const string ReferenceLayer0Output = Root + "/reference_layer0_output.f32";
	public const string ReferenceFinalLayerNorm = Root + "/reference_final_ln.f32";
	public const string ReferenceFinalLogitsLastPosition =
		Root + "/reference_final_logits_last_position.f32";
	public const string ReferenceGreedyGeneration =
		Root + "/reference_greedy_generation.json";
	public const string ReferenceGenerationStep11Logits =
		Root + "/reference_generation_step11_logits.f32";
	public const string ReferenceLayer1LocalMaskLen260 =
		Root + "/reference_layer1_local_mask_len260.bin";
	public const string ReferenceLayer1LocalMaskLen260Metadata =
		Root + "/reference_layer1_local_mask_len260.json";
	public const string Tokenizer = Root + "/tokenizer/tokenizer.json";
	public const string TokenizerConfig = Root + "/tokenizer/tokenizer_config.json";

	public static string ReferenceStage( string fileName )
	{
		if ( string.IsNullOrWhiteSpace( fileName ) || fileName.Contains( '/' ) ||
			fileName.Contains( '\\' ) || fileName.Contains( ".." ) )
		{
			throw new ArgumentException(
				$"[LLM:ERROR] Reference stage filename '{fileName}' is invalid.",
				nameof( fileName ) );
		}
		return Root + "/" + fileName;
	}
}