LCOV - code coverage report
Current view: top level - nntrainer/models - model_common_properties.h (source / functions) Coverage Total Hit
Test: coverage_filtered.info Lines: 100.0 % 13 13
Test Date: 2025-12-14 20:38:17 Functions: - 0 0

            Line data    Source code
       1              : // SPDX-License-Identifier: Apache-2.0
       2              : /**
       3              :  * Copyright (C) 2021 Jihoon Lee <jhoon.it.lee@samsung.com>
       4              :  *
       5              :  * @file   model_common_properties.h
       6              :  * @date   27 Aug 2021
       7              :  * @brief  This file contains common properties for model
       8              :  * @see    https://github.com/nnstreamer/nntrainer
       9              :  * @author Jihoon Lee <jhoon.it.lee@samsung.com>
      10              :  * @bug    No known bugs except for NYI items
      11              :  *
      12              :  */
      13              : #ifndef __MODEL_COMMON_PROPERTIES_H__
      14              : #define __MODEL_COMMON_PROPERTIES_H__
      15              : 
      16              : #include <base_properties.h>
      17              : 
      18              : #ifdef __cplusplus
      19              : namespace nntrainer::props {
      20              : 
      21              : /**
      22              :  * @brief model epoch property
      23              :  *
      24              :  */
      25         3990 : class Epochs : public PositiveIntegerProperty {
      26              : public:
      27              :   static constexpr const char *key = "epochs"; /**< unique key to access */
      28              :   using prop_tag = uint_prop_tag;              /**< property type */
      29              :   /**
      30              :    * @brief Construct a new Epochs object
      31              :    *
      32              :    * @param value value to set
      33              :    */
      34              :   Epochs(unsigned int value = 1);
      35              : };
      36              : 
      37              : /**
      38              :  * @brief model loss property (deprecated)
      39              :  *
      40              :  */
      41         3213 : class LossType : public Property<std::string> {
      42              : public:
      43              :   static constexpr const char *key = "loss"; /**< unique key to access */
      44              :   using prop_tag = str_prop_tag;             /**< property type */
      45              : 
      46              :   /**
      47              :    * @brief check if valid
      48              :    *
      49              :    * @param value value to check
      50              :    * @return bool true if valid
      51              :    */
      52              :   bool isValid(const std::string &value) const override;
      53              : };
      54              : 
      55              : /**
      56              :  * @brief model save path property
      57              :  *
      58              :  */
      59         2377 : class SavePath : public Property<std::string> {
      60              : public:
      61              :   static constexpr const char *key = "save_path"; /**< unique key to access */
      62              :   using prop_tag = str_prop_tag;                  /**< property type */
      63              : };
      64              : 
      65              : /**
      66              :  * @brief model save path property
      67              :  *
      68              :  */
      69         2377 : class SaveBestPath : public Property<std::string> {
      70              : public:
      71              :   static constexpr const char *key =
      72              :     "save_best_path";            /**< unique key to access */
      73              :   using prop_tag = str_prop_tag; /**< property type */
      74              : };
      75              : 
      76              : /**
      77              :  * @brief model batch size property
      78              :  *
      79              :  */
      80         4105 : class TrainingBatchSize : public PositiveIntegerProperty {
      81              : public:
      82              :   static constexpr const char *key = "batch_size"; /**< unique key to access */
      83              :   using prop_tag = uint_prop_tag;                  /**< property type */
      84              : 
      85              :   /**
      86              :    * @brief Construct a new Batch Size object
      87              :    *
      88              :    * @param value value to set, defaults to 1
      89              :    */
      90              :   TrainingBatchSize(unsigned int value = 1);
      91              : };
      92              : 
      93              : /**
      94              :  * @brief model continue property
      95              :  *
      96              :  */
      97         1541 : class ContinueTrain : public Property<bool> {
      98              : public:
      99              :   static constexpr const char *key =
     100              :     "continue_train";             /**< unique key to access */
     101              :   using prop_tag = bool_prop_tag; /**< property type */
     102              : 
     103              :   /**
     104              :    * @brief Constructor
     105              :    *
     106              :    * @param value value to set, defaults to false
     107              :    */
     108              :   ContinueTrain(bool value = false);
     109              : };
     110              : 
     111              : /**
     112              :  * @brief model optimization property
     113              :  *
     114              :  */
     115         1541 : class MemoryOptimization : public Property<bool> {
     116              : public:
     117              :   static constexpr const char *key =
     118              :     "memory_optimization";        /**< unique key to access */
     119              :   using prop_tag = bool_prop_tag; /**< property type */
     120              : 
     121              :   /**
     122              :    * @brief Constructor
     123              :    *
     124              :    * @param value value to set, defaults to true
     125              :    */
     126              :   MemoryOptimization(bool value = true);
     127              : };
     128              : 
     129              : /**
     130              :  * @brief cache size property
     131              :  *
     132              :  */
     133         1541 : class Fsu : public Property<bool> {
     134              : public:
     135              :   static constexpr const char *key = "fsu"; /**< unique key to access */
     136              :   using prop_tag = bool_prop_tag;           /**< property type */
     137              : 
     138              :   /**
     139              :    * @brief Constructor
     140              :    *
     141              :    * @param value value to set, defaults to false
     142              :    */
     143              :   Fsu(bool value = false);
     144              : };
     145              : 
     146              : /**
     147              :  * @brief cache file path property
     148              :  *
     149              :  */
     150         1541 : class FsuPath : public Property<std::string> {
     151              : public:
     152              :   static constexpr const char *key = "fsu_path"; /**< unique key to access */
     153              :   using prop_tag = str_prop_tag;                 /**< property type */
     154              : 
     155              :   /**
     156              :    * @brief Constructor
     157              :    *
     158              :    * @param value value to set, defaults to current directory
     159              :    */
     160              :   FsuPath(const std::string &value = ".");
     161              : };
     162              : 
     163              : /**
     164              :  * @brief cache file path property
     165              :  *
     166              :  */
     167         1541 : class FsuLookahead : public Property<unsigned int> {
     168              : public:
     169              :   static constexpr const char *key =
     170              :     "fsu_lookahead";              /**< unique key to access */
     171              :   using prop_tag = uint_prop_tag; /**< property type */
     172              : 
     173              :   /**
     174              :    * @brief Constructor
     175              :    *
     176              :    * @param value value to set, defaults to current directory
     177              :    */
     178         1672 :   FsuLookahead(const unsigned int &value = 0);
     179              : };
     180              : 
     181              : /**
     182              :  * @brief     Enumeration of Data Type for model & layer
     183              :  */
     184              : struct ModelTensorDataTypeInfo {
     185              :   enum Enum {
     186              :     W3A32,
     187              :     W4A16,
     188              :     W4A32,
     189              :     W8A16,
     190              :     W8A32,
     191              :     W16A16,
     192              :     W16A32,
     193              :     W32A16,
     194              :     W32A32,
     195              :     WQ16AQ16,
     196              :     WU16AU16,
     197              :     W8AU16,
     198              :     WU4AU8,
     199              :     WU4AU16,
     200              :     WU8AU8,
     201              :     WU8AU16,
     202              :     WQ4KA32,
     203              :     WQ40A32,
     204              :     WQ40A16,
     205              :   };
     206              :   static constexpr std::initializer_list<Enum> EnumList = {
     207              :     Enum::W3A32,    Enum::W4A16,   Enum::W4A32,   Enum::W8A16,   Enum::W8A32,
     208              :     Enum::W16A16,   Enum::W16A32,  Enum::W32A16,  Enum::W32A32,  Enum::WQ16AQ16,
     209              :     Enum::WU16AU16, Enum::W8AU16,  Enum::WU4AU8,  Enum::WU4AU16, Enum::WU8AU8,
     210              :     Enum::WU8AU16,  Enum::WQ4KA32, Enum::WQ40A32, Enum::WQ40A16,
     211              :   };
     212              : 
     213              :   static constexpr const char *EnumStr[] = {
     214              :     "BCQ-FP32",    "QINT4-FP16",    "QINT4-FP32",    "QINT8-FP16",
     215              :     "QINT8-FP32",  "FP16-FP16",     "FP16-FP32",     "FP32-FP16",
     216              :     "FP32-FP32",   "QINT16-QINT16", "UINT16-UINT16", "QINT8-UINT16",
     217              :     "UINT4-UINT8", "UINT4-UINT16",  "UINT8-UINT8",   "UINT8-UINT16",
     218              :     "Q4_K-FP32",   "Q4_0-FP32",     "Q4_0-FP16"};
     219              : };
     220              : 
     221              : /**
     222              :  * @brief Activation Enumeration Information
     223              :  *
     224              :  */
     225         2370 : class ModelTensorDataType final : public EnumProperty<ModelTensorDataTypeInfo> {
     226              : public:
     227              :   using prop_tag = enum_class_prop_tag;
     228              :   static constexpr const char *key = "model_tensor_type";
     229              : 
     230              :   /**
     231              :    * @brief Constructor
     232              :    *
     233              :    * @param value value to set, defaults to W32A32
     234              :    */
     235              :   ModelTensorDataType(ModelTensorDataTypeInfo::Enum value =
     236              :                         ModelTensorDataTypeInfo::Enum::W32A32);
     237              : };
     238              : 
     239              : /**
     240              :  * @brief LossScale property, loss is scaled by this value
     241              :  *
     242              :  */
     243         2377 : class LossScale : public Property<float> {
     244              : public:
     245              :   LossScale(float value = 1.0f);
     246              :   static constexpr const char *key = "loss_scale"; /**< unique key to access */
     247              :   using prop_tag = float_prop_tag;                 /**< property type */
     248              : 
     249              :   /**
     250              :    * @brief check if valid
     251              :    *
     252              :    * @param value value to check
     253              :    * @return bool true if valid
     254              :    */
     255              :   bool isValid(const float &value) const override;
     256              : };
     257              : 
     258              : } // namespace nntrainer::props
     259              : 
     260              : #endif
     261              : 
     262              : #endif // __MODEL_COMMON_PROPERTIES_H__
        

Generated by: LCOV version 2.0-1