Module: GPT2ConfigLoader
- Defined in:
- lib/toy/io/gguf_load.rb
Class Method Summary collapse
-
.read(path) ⇒ Object
Read all hyperparams from a GGUF file’s kv metadata.
Class Method Details
.read(path) ⇒ Object
Read all hyperparams from a GGUF file’s kv metadata. Returns a populated GPT2Config; the caller passes it to GPT2LM.new and the FFI cache realize_for methods.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/toy/io/gguf_load.rb', line 41 def self.read(path) handle = TinyNN.tnn_gguf_load(path) if handle == nil puts "GPT2ConfigLoader: failed to open " + path return GPT2Config.new(0, 0, 0, 0, 0, 0, 1.0e-5) end vocab = TinyNN.tnn_gguf_get_u32(handle, "gpt2.vocab_size") d_model = TinyNN.tnn_gguf_get_u32(handle, "gpt2.embedding_length") d_ff = TinyNN.tnn_gguf_get_u32(handle, "gpt2.feed_forward_length") n_head = TinyNN.tnn_gguf_get_u32(handle, "gpt2.attention.head_count") n_layer = TinyNN.tnn_gguf_get_u32(handle, "gpt2.block_count") ctx = TinyNN.tnn_gguf_get_u32(handle, "gpt2.context_length") eps = TinyNN.tnn_gguf_get_f32(handle, "gpt2.attention.layer_norm_epsilon") TinyNN.tnn_gguf_free(handle) GPT2Config.new(vocab, d_model, d_ff, n_head, n_layer, ctx, eps) end |