LLVM 20.0.0git
Public Member Functions | List of all members
llvm::Logger Class Referencefinal

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)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Logger()

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.

Member Function Documentation

◆ currentContext()

const std::string & llvm::Logger::currentContext ( ) const
inline

Definition at line 122 of file TrainingLogger.h.

◆ endObservation()

void Logger::endObservation ( )

Definition at line 68 of file TrainingLogger.cpp.

◆ flush()

void llvm::Logger::flush ( )
inline

Definition at line 120 of file TrainingLogger.h.

References OS.

◆ hasAnyObservationForContext()

bool llvm::Logger::hasAnyObservationForContext ( StringRef  Ctx) const
inline

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().

◆ hasObservationInProgress()

bool llvm::Logger::hasObservationInProgress ( ) const
inline

Check if there is at least an observation for currentContext().

Definition at line 125 of file TrainingLogger.h.

References hasAnyObservationForContext().

◆ logReward()

template<typename T >
void llvm::Logger::logReward ( T  Value)
inline

Definition at line 134 of file TrainingLogger.h.

◆ logTensorValue()

void llvm::Logger::logTensorValue ( size_t  FeatureID,
const char RawData 
)
inline

Definition at line 138 of file TrainingLogger.h.

◆ startObservation()

void Logger::startObservation ( )

◆ switchContext()

void Logger::switchContext ( StringRef  Name)

The documentation for this class was generated from the following files: