ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Config.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef __GGMA_CONFIG_H__
18#define __GGMA_CONFIG_H__
19
20#include "KVCache.h"
21
22#include <optional>
23#include <string>
24
25// Forward declaration for JSON
26namespace Json
27{
28class Value;
29}
30
31namespace ggma
32{
33
34// Structure to hold model architecture specific configuration.
35// This can be loaded from various model sources (e.g., Hugging Face, FairSeq).
37{
38 //--- ModelConfig
39 int n_layers; // Number of transformer layers
40 int hidden_size; // Hidden dimension
42 int vocab_size; // Vocabulary size
43 int max_position_embeddings; // Maximum sequence length
44 std::optional<int> bos_token_id;
45 std::optional<int> eos_token_id;
46
47 // Constructor with default values
49
50 // Load configuration from JSON file
51 void load_from_file(const std::string &config_path);
52
53 // Load configuration from JSON value
54 void load_from_json(const Json::Value &root);
55
56 // Validate configuration
57 bool is_valid() const;
58
59 // Get configuration as string (for debugging)
60 std::string to_string() const;
61};
62
63// Structure to hold all GGMA-specific configurations,
64// including both the model architecture and runtime/execution parameters.
66{
67 ModelConfig model; // Model architecture details
68 int cache_size = 32;
69 int ubatch = 32;
71};
72
73// Utility functions for ModelConfig
74bool validate_model_config(const ModelConfig &config);
75std::string to_string(const ModelConfig &config);
76
77} // namespace ggma
78
79#endif // __GGMA_CONFIG_H__
Definition Config.h:27
Definition Config.cc:24
KVCacheDataType
Definition KVCache.h:37
std::string to_string(const ModelConfig &config)
Definition Config.cc:144
bool validate_model_config(const ModelConfig &config)
Definition Config.cc:142
ModelConfig model
Definition Config.h:67
KVCacheDataType kv_cache_type
Definition Config.h:70
std::optional< int > eos_token_id
Definition Config.h:45
int max_position_embeddings
Definition Config.h:43
int num_attention_heads
Definition Config.h:41
bool is_valid() const
Definition Config.cc:100
void load_from_json(const Json::Value &root)
Definition Config.cc:87
void load_from_file(const std::string &config_path)
Definition Config.cc:61
std::optional< int > bos_token_id
Definition Config.h:44
std::string to_string() const
Definition Config.cc:124