tensors.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package model
  2. // Standard tensor names for various architectures
  3. // These constants helps in normalizing and identifying tensor roles across different models (Llama, Qwen, etc.)
  4. const (
  5. // Embeddings & Head
  6. TensorTokenEmbeddings = "embed_tokens"
  7. TensorOutputHead = "lm_head"
  8. TensorNorm = "norm"
  9. // Attention
  10. TensorAttnQ = "self_attn.q_proj"
  11. TensorAttnK = "self_attn.k_proj"
  12. TensorAttnV = "self_attn.v_proj"
  13. TensorAttnO = "self_attn.o_proj"
  14. TensorAttnNorm = "input_layernorm" // pre-attention norm
  15. // MLP / FFN
  16. TensorMlpGate = "mlp.gate_proj"
  17. TensorMlpUp = "mlp.up_proj"
  18. TensorMlpDown = "mlp.down_proj"
  19. TensorMlpNorm = "post_attention_layernorm" // pre-mlp norm
  20. // Biases (Common suffixes)
  21. SuffixWeight = ".weight"
  22. SuffixBias = ".bias"
  23. )
  24. // ImportantPattern defines a mapping between a conceptual role and a regex pattern
  25. type ImportantPattern struct {
  26. Role string
  27. Pattern string
  28. }
  29. // DefaultCriticalPatterns returns a list of patterns typically considered critical (sensitive)
  30. func DefaultCriticalPatterns() []string {
  31. return []string{
  32. "embed_tokens",
  33. "lm_head",
  34. }
  35. }