LLVM 20.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 | |
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. | |
void | switchContext (StringRef Name) |
void | startObservation () |
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 91 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.
|
inline |
Definition at line 122 of file TrainingLogger.h.
void Logger::endObservation | ( | ) |
Definition at line 68 of file TrainingLogger.cpp.
|
inline |
Definition at line 120 of file TrainingLogger.h.
References OS.
Check if there is at least an observation for the context Ctx
.
Definition at line 130 of file TrainingLogger.h.
References llvm::StringMap< ValueTy, AllocatorTy >::contains().
Referenced by hasObservationInProgress().
|
inline |
Check if there is at least an observation for currentContext()
.
Definition at line 125 of file TrainingLogger.h.
References hasAnyObservationForContext().
Definition at line 134 of file TrainingLogger.h.
Definition at line 138 of file TrainingLogger.h.
void Logger::startObservation | ( | ) |
Definition at line 58 of file TrainingLogger.cpp.
References llvm::json::OStream::attribute(), I, llvm::StringMap< ValueTy, AllocatorTy >::insert(), and llvm::json::OStream::object().
void Logger::switchContext | ( | StringRef | Name | ) |
Definition at line 51 of file TrainingLogger.cpp.
References llvm::json::OStream::attribute(), Name, and llvm::json::OStream::object().