llama: use f16 mask for FA to save VRAM (#23764)
* llama: use f16 mask for FA * review: add llama_cast + formatting * simplify
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include "ggml.h" // for ggml_log_level
|
||||
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __GNUC__
|
||||
@@ -40,6 +41,19 @@ struct no_init {
|
||||
no_init() = default;
|
||||
};
|
||||
|
||||
template <typename dst_t, typename src_t>
|
||||
static inline dst_t llama_cast(src_t v) {
|
||||
if constexpr (std::is_same_v<src_t, dst_t>) {
|
||||
return v;
|
||||
} else if constexpr (std::is_same_v<src_t, ggml_fp16_t> && std::is_same_v<dst_t, float>) {
|
||||
return ggml_fp16_to_fp32(v);
|
||||
} else if constexpr (std::is_same_v<src_t, float> && std::is_same_v<dst_t, ggml_fp16_t>) {
|
||||
return ggml_fp32_to_fp16(v);
|
||||
} else {
|
||||
static_assert(std::is_same_v<dst_t, void>, "unsupported type combination");
|
||||
}
|
||||
}
|
||||
|
||||
struct time_meas {
|
||||
time_meas(int64_t & t_acc, bool disable = false);
|
||||
~time_meas();
|
||||
|
||||
Reference in New Issue
Block a user