Class: Toy::Core::CLI::Describe

Inherits:
Object
  • Object
show all
Defined in:
lib/toy/core/cli/describe.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Describe

Returns a new instance of Describe.



26
27
28
29
30
# File 'lib/toy/core/cli/describe.rb', line 26

def initialize(argv)
  @argv = argv
  @json = false
  @model = nil
end

Instance Method Details

#runObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/toy/core/cli/describe.rb', line 32

def run
  return EXIT_BAD_INPUT unless parse_args
  path = File.expand_path(@model)

  unless File.file?(path)
    return fail_out("no such file: #{path}")
  end

  begin
    meta = GGUFMeta.read(path)
  rescue GGUFMeta::ParseError => e
    return fail_out("could not parse GGUF: #{e.message}")
  end

  arch = ModelScan.read_arch(meta)
  if arch.nil?
    return fail_out("#{path}: no recognizable transformer arch metadata in GGUF")
  end
  # `describe` renders the toy's llama-family Card (GQA + SwiGLU +
  # RoPE). Other arches (gpt2, gemma2, olmoe, ...) are genuinely
  # different — decline rather than render a confident wrong card.
  unless [:llama, :qwen2].include?(arch[:family])
    return fail_out(
      "#{path}: #{arch[:family]} model — `toy describe` renders the " \
      "llama-family Card (llama/qwen2) only; #{arch[:family]} has a " \
      "different architecture. Read dims: V=#{arch[:vocab]} " \
      "D=#{arch[:d_model]} L=#{arch[:n_layers]} n_q=#{arch[:n_q]} " \
      "n_kv=#{arch[:n_kv]} d_ff=#{arch[:d_ff]}.")
  end
  arch[:n_params] = ModelScan.estimate_params(arch)

  if @json
    emit_json(path, arch)
  else
    emit_human(path, arch)
  end
  EXIT_OK
end