Skip to content

Commit 59cf3c0

Browse files
committed
Revert commit 'ab86335760ebb441574eb47f886fa1ee302e2131'
1 parent 0d4ddc7 commit 59cf3c0

File tree

20 files changed

+229
-458
lines changed

20 files changed

+229
-458
lines changed

common/arg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1680,7 +1680,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
16801680
[](common_params & params) {
16811681
params.warmup = false;
16821682
}
1683-
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_EMBEDDING, LLAMA_EXAMPLE_RETRIEVAL}));
1683+
).set_examples({LLAMA_EXAMPLE_MAIN, LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_EMBEDDING}));
16841684
add_opt(common_arg(
16851685
{"--spm-infill"},
16861686
string_format(

convert_hf_to_gguf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,7 +2645,7 @@ def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iter
26452645
yield from super().modify_tensors(data_torch, name, bid)
26462646

26472647

2648-
@ModelBase.register("Qwen2VLModel", "Qwen2VLForConditionalGeneration", "Qwen2_5_VLForConditionalGeneration")
2648+
@ModelBase.register("Qwen2VLForConditionalGeneration", "Qwen2_5_VLForConditionalGeneration")
26492649
class Qwen2VLModel(TextModel):
26502650
model_arch = gguf.MODEL_ARCH.QWEN2VL
26512651

@@ -2669,7 +2669,7 @@ def modify_tensors(self, data_torch: Tensor, name: str, bid: int | None) -> Iter
26692669
return [(self.map_tensor_name(name), data_torch)]
26702670

26712671

2672-
@ModelBase.register("Qwen2VLModel", "Qwen2VLForConditionalGeneration", "Qwen2_5_VLForConditionalGeneration")
2672+
@ModelBase.register("Qwen2VLForConditionalGeneration", "Qwen2_5_VLForConditionalGeneration")
26732673
class Qwen2VLVisionModel(VisionModel):
26742674
def __init__(self, *args, **kwargs):
26752675
super().__init__(*args, **kwargs)

ggml/include/ggml.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -651,15 +651,14 @@ extern "C" {
651651
GGML_UNARY_OP_STEP,
652652
GGML_UNARY_OP_TANH,
653653
GGML_UNARY_OP_ELU,
654+
GGML_UNARY_OP_RELU,
654655
GGML_UNARY_OP_SIGMOID,
655656
GGML_UNARY_OP_GELU,
656-
GGML_UNARY_OP_GELU_ERF,
657657
GGML_UNARY_OP_GELU_QUICK,
658658
GGML_UNARY_OP_SILU,
659659
GGML_UNARY_OP_HARDSWISH,
660660
GGML_UNARY_OP_HARDSIGMOID,
661661
GGML_UNARY_OP_EXP,
662-
GGML_UNARY_OP_RELU,
663662

664663
GGML_UNARY_OP_COUNT,
665664
};
@@ -1153,16 +1152,6 @@ extern "C" {
11531152
struct ggml_context * ctx,
11541153
struct ggml_tensor * a);
11551154

1156-
// GELU using erf (error function) when possible
1157-
// some backends may fallback to approximation based on Abramowitz and Stegun formula
1158-
GGML_API struct ggml_tensor * ggml_gelu_erf(
1159-
struct ggml_context * ctx,
1160-
struct ggml_tensor * a);
1161-
1162-
GGML_API struct ggml_tensor * ggml_gelu_erf_inplace(
1163-
struct ggml_context * ctx,
1164-
struct ggml_tensor * a);
1165-
11661155
GGML_API struct ggml_tensor * ggml_gelu_quick(
11671156
struct ggml_context * ctx,
11681157
struct ggml_tensor * a);

ggml/src/ggml-cpu/ggml-cpu.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2579,7 +2579,6 @@ static int ggml_get_n_tasks(struct ggml_tensor * node, int n_threads) {
25792579
} break;
25802580

25812581
case GGML_UNARY_OP_GELU:
2582-
case GGML_UNARY_OP_GELU_ERF:
25832582
case GGML_UNARY_OP_GELU_QUICK:
25842583
case GGML_UNARY_OP_SILU:
25852584
{

ggml/src/ggml-cpu/ops.cpp

Lines changed: 0 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,109 +2824,6 @@ static void ggml_compute_forward_gelu(
28242824
}
28252825
}
28262826

2827-
// ggml_compute_forward_gelu_erf
2828-
2829-
static void ggml_compute_forward_gelu_erf_f32(
2830-
const ggml_compute_params * params,
2831-
ggml_tensor * dst) {
2832-
2833-
const ggml_tensor * src0 = dst->src[0];
2834-
2835-
assert(ggml_is_contiguous_1(src0));
2836-
assert(ggml_is_contiguous_1(dst));
2837-
assert(ggml_are_same_shape(src0, dst));
2838-
2839-
const int ith = params->ith;
2840-
const int nth = params->nth;
2841-
2842-
const int nc = src0->ne[0];
2843-
const int nr = ggml_nrows(src0);
2844-
2845-
// rows per thread
2846-
const int dr = (nr + nth - 1)/nth;
2847-
2848-
// row range for this thread
2849-
const int ir0 = dr*ith;
2850-
const int ir1 = MIN(ir0 + dr, nr);
2851-
2852-
for (int i1 = ir0; i1 < ir1; i1++) {
2853-
ggml_vec_gelu_erf_f32(nc,
2854-
(float *) ((char *) dst->data + i1*( dst->nb[1])),
2855-
(float *) ((char *) src0->data + i1*(src0->nb[1])));
2856-
2857-
#ifndef NDEBUG
2858-
for (int k = 0; k < nc; k++) {
2859-
const float x = ((float *) ((char *) dst->data + i1*( dst->nb[1])))[k];
2860-
GGML_UNUSED(x);
2861-
assert(!isnan(x));
2862-
assert(!isinf(x));
2863-
}
2864-
#endif
2865-
}
2866-
}
2867-
2868-
static void ggml_compute_forward_gelu_erf_f16(
2869-
const ggml_compute_params * params,
2870-
ggml_tensor * dst) {
2871-
2872-
const ggml_tensor * src0 = dst->src[0];
2873-
2874-
assert(ggml_is_contiguous_1(src0));
2875-
assert(ggml_is_contiguous_1(dst));
2876-
assert(ggml_are_same_shape(src0, dst));
2877-
2878-
const int ith = params->ith;
2879-
const int nth = params->nth;
2880-
2881-
const int nc = src0->ne[0];
2882-
const int nr = ggml_nrows(src0);
2883-
2884-
// rows per thread
2885-
const int dr = (nr + nth - 1)/nth;
2886-
2887-
// row range for this thread
2888-
const int ir0 = dr*ith;
2889-
const int ir1 = MIN(ir0 + dr, nr);
2890-
2891-
for (int i1 = ir0; i1 < ir1; i1++) {
2892-
ggml_vec_gelu_erf_f16(nc,
2893-
(ggml_fp16_t *) ((char *) dst->data + i1*( dst->nb[1])),
2894-
(ggml_fp16_t *) ((char *) src0->data + i1*(src0->nb[1])));
2895-
2896-
#ifndef NDEBUG
2897-
for (int k = 0; k < nc; k++) {
2898-
const ggml_fp16_t x = ((ggml_fp16_t *) ((char *) dst->data + i1*( dst->nb[1])))[k];
2899-
const float v = GGML_FP16_TO_FP32(x);
2900-
GGML_UNUSED(v);
2901-
assert(!isnan(v));
2902-
assert(!isinf(v));
2903-
}
2904-
#endif
2905-
}
2906-
}
2907-
2908-
static void ggml_compute_forward_gelu_erf(
2909-
const ggml_compute_params * params,
2910-
ggml_tensor * dst) {
2911-
2912-
const ggml_tensor * src0 = dst->src[0];
2913-
2914-
switch (src0->type) {
2915-
case GGML_TYPE_F32:
2916-
{
2917-
ggml_compute_forward_gelu_erf_f32(params, dst);
2918-
} break;
2919-
case GGML_TYPE_F16:
2920-
{
2921-
ggml_compute_forward_gelu_erf_f16(params, dst);
2922-
} break;
2923-
default:
2924-
{
2925-
GGML_ABORT("fatal error");
2926-
}
2927-
}
2928-
}
2929-
29302827
// ggml_compute_forward_gelu_quick
29312828

29322829
static void ggml_compute_forward_gelu_quick_f32(
@@ -8356,10 +8253,6 @@ void ggml_compute_forward_unary(
83568253
{
83578254
ggml_compute_forward_gelu(params, dst);
83588255
} break;
8359-
case GGML_UNARY_OP_GELU_ERF:
8360-
{
8361-
ggml_compute_forward_gelu_erf(params, dst);
8362-
} break;
83638256
case GGML_UNARY_OP_GELU_QUICK:
83648257
{
83658258
ggml_compute_forward_gelu_quick(params, dst);

ggml/src/ggml-cpu/vec.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ inline static void ggml_vec_exp_f16 (const int n, ggml_fp16_t * y, const ggml_fp
428428
static const float GELU_COEF_A = 0.044715f;
429429
static const float GELU_QUICK_COEF = -1.702f;
430430
static const float SQRT_2_OVER_PI = 0.79788456080286535587989211986876f;
431-
static const float SQRT_2_INV = 0.70710678118654752440084436210484f;
432431

433432
inline static float ggml_gelu_f32(float x) {
434433
return 0.5f*x*(1.0f + tanhf(SQRT_2_OVER_PI*x*(1.0f + GELU_COEF_A*x*x)));
@@ -441,14 +440,6 @@ inline static float ggml_gelu_f32(float x) {
441440
}
442441
}
443442
444-
inline static void ggml_vec_gelu_erf_f16(const int n, ggml_fp16_t * y, const ggml_fp16_t * x) {
445-
for (int i = 0; i < n; ++i) {
446-
float xi = GGML_FP16_TO_FP32(x[i]);
447-
float res = 0.5f*xi*(1.0f + erff(xi*SQRT_2_INV));
448-
y[i] = GGML_FP32_TO_FP16(res);
449-
}
450-
}
451-
452443
#ifdef GGML_GELU_FP16
453444
inline static void ggml_vec_gelu_f32(const int n, float * y, const float * x) {
454445
uint16_t t;
@@ -472,13 +463,6 @@ inline static void ggml_vec_gelu_f32(const int n, float * y, const float * x) {
472463
}
473464
#endif */
474465

475-
inline static void ggml_vec_gelu_erf_f32(const int n, float * y, const float * x) {
476-
for (int i = 0; i < n; ++i) {
477-
float xi = x[i];
478-
y[i] = 0.5f*xi*(1.0f + erff(xi*SQRT_2_INV));
479-
}
480-
}
481-
482466
inline static float ggml_gelu_quick_f32(float x) {
483467
return x*(1.0f/(1.0f+expf(GELU_QUICK_COEF*x)));
484468
}

ggml/src/ggml-metal/ggml-metal.metal

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,6 @@ kernel void kernel_tanh(
874874
constant float GELU_COEF_A = 0.044715f;
875875
constant float GELU_QUICK_COEF = -1.702f;
876876
constant float SQRT_2_OVER_PI = 0.79788456080286535587989211986876f;
877-
constant float SQRT_2_INV = 0.70710678118654752440084436210484f;
878877

879878
kernel void kernel_gelu(
880879
device const float * src0,
@@ -916,42 +915,6 @@ kernel void kernel_gelu_quick_4(
916915
dst[tpig] = x*(1.0f/(1.0f+exp(GELU_QUICK_COEF*x)));
917916
}
918917

919-
// based on Abramowitz and Stegun formula 7.1.26 or similar Hastings' approximation
920-
// ref: https://www.johndcook.com/blog/python_erf/
921-
constant float p_erf = 0.3275911f;
922-
constant float a1_erf = 0.254829592f;
923-
constant float a2_erf = -0.284496736f;
924-
constant float a3_erf = 1.421413741f;
925-
constant float a4_erf = -1.453152027f;
926-
constant float a5_erf = 1.061405429f;
927-
928-
template<typename T>
929-
T erf_approx(T x) {
930-
T sign_x = sign(x);
931-
x = fabs(x);
932-
T t = 1.0f / (1.0f + p_erf * x);
933-
T y = 1.0f - (((((a5_erf * t + a4_erf) * t) + a3_erf) * t + a2_erf) * t + a1_erf) * t * exp(-x * x);
934-
return sign_x * y;
935-
}
936-
937-
kernel void kernel_gelu_erf(
938-
device const float * src0,
939-
device float * dst,
940-
uint tpig[[thread_position_in_grid]]) {
941-
device const float & x = src0[tpig];
942-
943-
dst[tpig] = 0.5f*x*(1.0f+erf_approx<float>(x*SQRT_2_INV));
944-
}
945-
946-
kernel void kernel_gelu_erf_4(
947-
device const float4 * src0,
948-
device float4 * dst,
949-
uint tpig[[thread_position_in_grid]]) {
950-
device const float4 & x = src0[tpig];
951-
952-
dst[tpig] = 0.5f*x*(1.0f+erf_approx<float4>(x*SQRT_2_INV));
953-
}
954-
955918
kernel void kernel_silu(
956919
device const float * src0,
957920
device float * dst,

ggml/src/ggml.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1918,10 +1918,9 @@ static const char * GGML_UNARY_OP_NAME[GGML_UNARY_OP_COUNT] = {
19181918
"HARDSWISH",
19191919
"HARDSIGMOID",
19201920
"EXP",
1921-
"GELU_ERF",
19221921
};
19231922

1924-
static_assert(GGML_UNARY_OP_COUNT == 15, "GGML_UNARY_OP_COUNT != 15");
1923+
static_assert(GGML_UNARY_OP_COUNT == 14, "GGML_UNARY_OP_COUNT != 14");
19251924

19261925

19271926
static_assert(sizeof(struct ggml_object)%GGML_MEM_ALIGN == 0, "ggml_object size must be a multiple of GGML_MEM_ALIGN");
@@ -3375,20 +3374,6 @@ struct ggml_tensor * ggml_gelu_inplace(
33753374
return ggml_unary_inplace(ctx, a, GGML_UNARY_OP_GELU);
33763375
}
33773376

3378-
// ggml_gelu_erf
3379-
3380-
struct ggml_tensor * ggml_gelu_erf(
3381-
struct ggml_context * ctx,
3382-
struct ggml_tensor * a) {
3383-
return ggml_unary(ctx, a, GGML_UNARY_OP_GELU_ERF);
3384-
}
3385-
3386-
struct ggml_tensor * ggml_gelu_erf_inplace(
3387-
struct ggml_context * ctx,
3388-
struct ggml_tensor * a) {
3389-
return ggml_unary_inplace(ctx, a, GGML_UNARY_OP_GELU_ERF);
3390-
}
3391-
33923377
// ggml_gelu_quick
33933378

33943379
struct ggml_tensor * ggml_gelu_quick(

gguf-py/gguf/gguf_reader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def _get_field_parts(
251251
offs += curr_size
252252
return offs - orig_offs, aparts, data_idxs, types
253253
# We can't deal with this one.
254-
raise ValueError(f'Unknown/unhandled field type {gtype}')
254+
raise ValueError('Unknown/unhandled field type {gtype}')
255255

256256
def _get_tensor_info_field(self, orig_offs: int) -> ReaderField:
257257
offs = orig_offs

gguf-py/gguf/gguf_writer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ def add_add_space_prefix(self, value: bool) -> None:
896896
def add_remove_extra_whitespaces(self, value: bool) -> None:
897897
self.add_bool(Keys.Tokenizer.REMOVE_EXTRA_WS, value)
898898

899-
def add_precompiled_charsmap(self, charsmap: bytes) -> None:
899+
def add_precompiled_charsmap(self, charsmap: Sequence[bytes]) -> None:
900900
self.add_array(Keys.Tokenizer.PRECOMPILED_CHARSMAP, charsmap)
901901

902902
def add_chat_template(self, value: str | Sequence[Mapping[str, str]]) -> None:

0 commit comments

Comments
 (0)