220
220
#include <stdio.h>
221
221
222
222
#define GGML_FILE_MAGIC 0x67676d6c // "ggml"
223
- #define GGML_FILE_VERSION 1
223
+ #define GGML_FILE_VERSION 2
224
224
225
225
#define GGML_QNT_VERSION 2 // bump this on quantization format changes
226
226
#define GGML_QNT_VERSION_FACTOR 1000 // do not change this
@@ -453,6 +453,8 @@ extern "C" {
453
453
GGML_OP_SQR ,
454
454
GGML_OP_SQRT ,
455
455
GGML_OP_LOG ,
456
+ GGML_OP_SIN ,
457
+ GGML_OP_COS ,
456
458
GGML_OP_SUM ,
457
459
GGML_OP_SUM_ROWS ,
458
460
GGML_OP_MEAN ,
@@ -490,9 +492,11 @@ extern "C" {
490
492
GGML_OP_CLAMP ,
491
493
GGML_OP_CONV_TRANSPOSE_1D ,
492
494
GGML_OP_IM2COL ,
495
+ GGML_OP_IM2COL_BACK ,
493
496
GGML_OP_CONV_TRANSPOSE_2D ,
494
497
GGML_OP_POOL_1D ,
495
498
GGML_OP_POOL_2D ,
499
+ GGML_OP_POOL_2D_BACK ,
496
500
GGML_OP_UPSCALE , // nearest interpolate
497
501
GGML_OP_PAD ,
498
502
GGML_OP_ARANGE ,
@@ -969,6 +973,22 @@ extern "C" {
969
973
struct ggml_context * ctx ,
970
974
struct ggml_tensor * a );
971
975
976
+ GGML_API struct ggml_tensor * ggml_sin (
977
+ struct ggml_context * ctx ,
978
+ struct ggml_tensor * a );
979
+
980
+ GGML_API struct ggml_tensor * ggml_sin_inplace (
981
+ struct ggml_context * ctx ,
982
+ struct ggml_tensor * a );
983
+
984
+ GGML_API struct ggml_tensor * ggml_cos (
985
+ struct ggml_context * ctx ,
986
+ struct ggml_tensor * a );
987
+
988
+ GGML_API struct ggml_tensor * ggml_cos_inplace (
989
+ struct ggml_context * ctx ,
990
+ struct ggml_tensor * a );
991
+
972
992
// return scalar
973
993
GGML_API struct ggml_tensor * ggml_sum (
974
994
struct ggml_context * ctx ,
@@ -1566,34 +1586,49 @@ extern "C" {
1566
1586
float min ,
1567
1587
float max );
1568
1588
1589
+ // im2col
1590
+ // converts data into a format that effectively results in a convolution when combined with matrix multiplication
1569
1591
GGML_API struct ggml_tensor * ggml_im2col (
1570
1592
struct ggml_context * ctx ,
1571
- struct ggml_tensor * a ,
1572
- struct ggml_tensor * b ,
1573
- int s0 ,
1574
- int s1 ,
1575
- int p0 ,
1576
- int p1 ,
1577
- int d0 ,
1578
- int d1 ,
1579
- bool is_2D ,
1580
- enum ggml_type dst_type );
1593
+ struct ggml_tensor * a , // convolution kernel
1594
+ struct ggml_tensor * b , // data
1595
+ int s0 , // stride dimension 0
1596
+ int s1 , // stride dimension 1
1597
+ int p0 , // padding dimension 0
1598
+ int p1 , // padding dimension 1
1599
+ int d0 , // dilation dimension 0
1600
+ int d1 , // dilation dimension 1
1601
+ bool is_2D ,
1602
+ enum ggml_type dst_type );
1603
+
1604
+ GGML_API struct ggml_tensor * ggml_im2col_back (
1605
+ struct ggml_context * ctx ,
1606
+ struct ggml_tensor * a , // convolution kernel
1607
+ struct ggml_tensor * b , // gradient of im2col output
1608
+ int64_t * ne , // shape of im2col input
1609
+ int s0 , // stride dimension 0
1610
+ int s1 , // stride dimension 1
1611
+ int p0 , // padding dimension 0
1612
+ int p1 , // padding dimension 1
1613
+ int d0 , // dilation dimension 0
1614
+ int d1 , // dilation dimension 1
1615
+ bool is_2D );
1581
1616
1582
1617
GGML_API struct ggml_tensor * ggml_conv_depthwise_2d (
1583
1618
struct ggml_context * ctx ,
1584
- struct ggml_tensor * a ,
1585
- struct ggml_tensor * b ,
1586
- int s0 ,
1587
- int s1 ,
1588
- int p0 ,
1589
- int p1 ,
1590
- int d0 ,
1591
- int d1 );
1619
+ struct ggml_tensor * a , // convolution kernel
1620
+ struct ggml_tensor * b , // data
1621
+ int s0 , // stride dimension 0
1622
+ int s1 , // stride dimension 1
1623
+ int p0 , // padding dimension 0
1624
+ int p1 , // padding dimension 1
1625
+ int d0 , // dilation dimension 0
1626
+ int d1 ); // dilation dimension 1
1592
1627
1593
1628
GGML_API struct ggml_tensor * ggml_conv_1d (
1594
1629
struct ggml_context * ctx ,
1595
- struct ggml_tensor * a ,
1596
- struct ggml_tensor * b ,
1630
+ struct ggml_tensor * a , // convolution kernel
1631
+ struct ggml_tensor * b , // data
1597
1632
int s0 , // stride
1598
1633
int p0 , // padding
1599
1634
int d0 ); // dilation
@@ -1602,29 +1637,29 @@ extern "C" {
1602
1637
// alias for ggml_conv_1d(a, b, s, a->ne[0]/2, d)
1603
1638
GGML_API struct ggml_tensor * ggml_conv_1d_ph (
1604
1639
struct ggml_context * ctx ,
1605
- struct ggml_tensor * a ,
1606
- struct ggml_tensor * b ,
1607
- int s ,
1608
- int d );
1640
+ struct ggml_tensor * a , // convolution kernel
1641
+ struct ggml_tensor * b , // data
1642
+ int s , // stride
1643
+ int d ); // dilation
1609
1644
1610
1645
GGML_API struct ggml_tensor * ggml_conv_transpose_1d (
1611
1646
struct ggml_context * ctx ,
1612
- struct ggml_tensor * a ,
1613
- struct ggml_tensor * b ,
1614
- int s0 ,
1615
- int p0 ,
1616
- int d0 );
1647
+ struct ggml_tensor * a , // convolution kernel
1648
+ struct ggml_tensor * b , // data
1649
+ int s0 , // stride
1650
+ int p0 , // padding
1651
+ int d0 ); // dilation
1617
1652
1618
1653
GGML_API struct ggml_tensor * ggml_conv_2d (
1619
1654
struct ggml_context * ctx ,
1620
- struct ggml_tensor * a ,
1621
- struct ggml_tensor * b ,
1622
- int s0 ,
1623
- int s1 ,
1624
- int p0 ,
1625
- int p1 ,
1626
- int d0 ,
1627
- int d1 );
1655
+ struct ggml_tensor * a , // convolution kernel
1656
+ struct ggml_tensor * b , // data
1657
+ int s0 , // stride dimension 0
1658
+ int s1 , // stride dimension 1
1659
+ int p0 , // padding dimension 0
1660
+ int p1 , // padding dimension 1
1661
+ int d0 , // dilation dimension 0
1662
+ int d1 ); // dilation dimension 1
1628
1663
1629
1664
1630
1665
// kernel size is a->ne[0] x a->ne[1]
@@ -1686,6 +1721,18 @@ extern "C" {
1686
1721
float p0 ,
1687
1722
float p1 );
1688
1723
1724
+ GGML_API struct ggml_tensor * ggml_pool_2d_back (
1725
+ struct ggml_context * ctx ,
1726
+ struct ggml_tensor * a ,
1727
+ struct ggml_tensor * af , // "a"/input used in forward pass
1728
+ enum ggml_op_pool op ,
1729
+ int k0 ,
1730
+ int k1 ,
1731
+ int s0 ,
1732
+ int s1 ,
1733
+ float p0 ,
1734
+ float p1 );
1735
+
1689
1736
// nearest interpolate
1690
1737
// multiplies ne0 and ne1 by scale factor
1691
1738
// used in stable-diffusion
0 commit comments