LLVM 22.0.0git
|
Logging utility - given an ordered specification of features, and assuming a scalar reward, allow logging feature values and rewards. More...
#include "llvm/Analysis/Utils/TrainingLogger.h"
Public Member Functions | |
LLVM_ABI | Logger (std::unique_ptr< raw_ostream > OS, const std::vector< TensorSpec > &FeatureSpecs, const TensorSpec &RewardSpec, bool IncludeReward, std::optional< TensorSpec > AdviceSpec=std::nullopt) |
Construct a Logger. | |
LLVM_ABI void | switchContext (StringRef Name) |
LLVM_ABI void | startObservation () |
LLVM_ABI void | endObservation () |
void | flush () |
const std::string & | currentContext () const |
bool | hasObservationInProgress () const |
Check if there is at least an observation for currentContext(). | |
bool | hasAnyObservationForContext (StringRef Ctx) const |
Check if there is at least an observation for the context Ctx. | |
template<typename T> | |
void | logReward (T Value) |
void | logTensorValue (size_t FeatureID, const char *RawData) |
Logging utility - given an ordered specification of features, and assuming a scalar reward, allow logging feature values and rewards.
The assumption is that, for an event to be logged (i.e. a set of feature values and a reward), the user calls the log* API for each feature exactly once, providing the index matching the position in the feature spec list provided at construction. The example assumes the first feature's element type is float, the second is int64, and the reward is float:
event 0: logFloatValue(0, ...) logInt64Value(1, ...) ... logFloatReward(...) event 1: logFloatValue(0, ...) logInt64Value(1, ...) ... logFloatReward(...)
At the end, call print to generate the log. Alternatively, don't call logReward at the end of each event, just log{Float|Int32|Int64}FinalReward at the end.
Definition at line 92 of file TrainingLogger.h.
Logger::Logger | ( | std::unique_ptr< raw_ostream > | OS, |
const std::vector< TensorSpec > & | FeatureSpecs, | ||
const TensorSpec & | RewardSpec, | ||
bool | IncludeReward, | ||
std::optional< TensorSpec > | AdviceSpec = std::nullopt ) |
Construct a Logger.
If IncludeReward is false, then logReward or logFinalReward shouldn't be called, and the reward feature won't be printed out. NOTE: the FeatureSpecs are expected to be in the same order (i.e. have corresponding indices) with any MLModelRunner implementations corresponding to the model being trained/logged.
Definition at line 82 of file TrainingLogger.cpp.
References llvm::move().
|
inline |
Definition at line 123 of file TrainingLogger.h.
void Logger::endObservation | ( | ) |
Definition at line 68 of file TrainingLogger.cpp.
|
inline |
Definition at line 121 of file TrainingLogger.h.
Check if there is at least an observation for the context Ctx.
Definition at line 131 of file TrainingLogger.h.
Referenced by hasObservationInProgress().
|
inline |
Check if there is at least an observation for currentContext().
Definition at line 126 of file TrainingLogger.h.
References hasAnyObservationForContext().
Definition at line 135 of file TrainingLogger.h.
References T.
Definition at line 139 of file TrainingLogger.h.
void Logger::startObservation | ( | ) |
Definition at line 58 of file TrainingLogger.cpp.
References llvm::json::OStream::attribute(), I, and llvm::json::OStream::object().
void Logger::switchContext | ( | StringRef | Name | ) |
Definition at line 51 of file TrainingLogger.cpp.
References llvm::json::OStream::attribute(), and llvm::json::OStream::object().