chatglm
mindnlp.transformers.models.chatglm.modeling_chatglm.CHATGLM_6B_PRETRAINED_MODEL_ARCHIVE_LIST = ['THUDM/chatglm-6b']
module-attribute
¶
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMModel
¶
Bases: ChatGLMPreTrainedModel
The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer of cross-attention is added between the self-attention layers, following the architecture described in Attention is all you need by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser and Illia Polosukhin.
To behave as an decoder the model needs to be initialized with the
is_decoder
argument of the configuration set to True
.
To be used in a Seq2Seq model, the model needs to initialized with both is_decoder
argument and add_cross_attention
set to True
; an
encoder_hidden_states
is then expected as an input to the forward pass.
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMModel.__init__(config)
¶
Initializes a ChatGLMModel object with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMModel class.
|
config |
An object containing configuration parameters for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If any of the configuration parameters are invalid or missing. |
TypeError
|
If the data types of the configuration parameters are incorrect. |
RuntimeError
|
If an error occurs during the initialization process. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMModel.forward(input_ids=None, position_ids=None, attention_mask=None, past_key_values=None, inputs_embeds=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
Constructs the ChatGLMModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The object itself.
|
input_ids |
The input tensor containing the IDs of the tokens. Defaults to None.
TYPE:
|
position_ids |
The input tensor containing the IDs of the positions. Defaults to None.
TYPE:
|
attention_mask |
The input tensor containing the attention mask. Defaults to None.
TYPE:
|
past_key_values |
The input tensor containing the past key values. Defaults to None.
TYPE:
|
inputs_embeds |
The input tensor containing the embedded inputs. Defaults to None.
TYPE:
|
use_cache |
Specifies whether to use cache. Defaults to None.
TYPE:
|
output_attentions |
Specifies whether to output attentions. Defaults to None.
TYPE:
|
output_hidden_states |
Specifies whether to output hidden states. Defaults to None.
TYPE:
|
return_dict |
Specifies whether to return a dictionary. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Tuple[Tensor, ...], BaseModelOutputWithPast]
|
Union[Tuple[mindspore.Tensor, ...], BaseModelOutputWithPast]: The output of the model. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If both input_ids and inputs_embeds are specified. |
ValueError
|
If neither input_ids nor inputs_embeds are specified. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMModel.get_input_embeddings()
¶
Returns the word embeddings for the input data.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLMModel class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
This method retrieves the word embeddings used for the input data in the ChatGLMModel. The word embeddings are a numerical representation of words that capture semantic meaning. The embeddings are trained on a large corpus of text data to capture relationships between words.
Note that this method does not modify the input embeddings. It simply returns the existing word embeddings that have been set for the model.
Example
>>> model = ChatGLMModel()
>>> input_embeddings = model.get_input_embeddings()
...
>>> # Perform operations on input_embeddings
...
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMModel.get_prompt(batch_size, dtype=mindspore.float16)
¶
This method retrieves the prompt for generating responses in the ChatGLMModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMModel class.
TYPE:
|
batch_size |
The number of prompt sequences to generate.
TYPE:
|
dtype |
The data type for the prompt key values. Default is mindspore.float16.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the batch_size is not an integer. |
ValueError
|
If the batch_size is less than or equal to 0. |
TypeError
|
If the dtype is not a valid mindspore data type. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMModel.set_input_embeddings(new_embeddings)
¶
This method sets the input embeddings for the ChatGLMModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMModel class.
TYPE:
|
new_embeddings |
The new embeddings to be set as input embeddings for the model. It should be a mindspore Tensor object.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMPreTrainedModel
¶
Bases: PreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMPreTrainedModel.get_masks(input_ids)
¶
This method named 'get_masks' is defined within the class 'ChatGLMPreTrainedModel'. It takes two parameters: self and input_ids.
PARAMETER | DESCRIPTION |
---|---|
self |
A reference to the instance of the class.
|
input_ids |
A tensor representing the input sequence of token IDs. It has a shape of (batch_size, seq_length) where batch_size is the number of input sequences and seq_length is the length of each sequence.
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMPreTrainedModel.get_position_ids(input_ids, mask_positions, use_gmasks=None)
¶
This method calculates the position ids for the given input sequence.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLMPreTrainedModel class.
TYPE:
|
input_ids |
A 2D tensor of shape (batch_size, seq_length) containing input sequence ids.
TYPE:
|
mask_positions |
A 1D tensor of shape (batch_size,) containing mask positions.
TYPE:
|
use_gmasks |
A list of length batch_size indicating whether to use global masks for each input sequence. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
position_ids
|
A 2D tensor of shape (batch_size, seq_length) containing the position ids.
TYPE:
|
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMForConditionalGeneration
¶
Bases: ChatGLMPreTrainedModel
This class represents a ChatGLM model for conditional generation, inheriting from ChatGLMPreTrainedModel.
The class includes methods for initializing the model, updating model keyword arguments for generation, preparing inputs for generation, forwarding the model, reordering cache for beam search or beam sample, processing model responses, and facilitating chat interactions. It also provides methods for streaming chat and generation.
The model allows for quantization with a specified number of bits.
METHOD | DESCRIPTION |
---|---|
__init__ |
Initializes the model with a ChatGLMConfig. |
get_output_embeddings |
Returns the output embeddings. |
set_output_embeddings |
Sets new output embeddings. |
_update_model_kwargs_for_generation |
Updates model keyword arguments for generation. |
prepare_inputs_for_generation |
Prepares inputs for model generation. |
forward |
Constructs the model for generation and computes the loss if labels are provided. |
_reorder_cache |
Reorders the past_key_values cache for beam search or beam sample. |
process_response |
Processes the model response by replacing tokens and punctuations. |
chat |
Conducts a chat interaction based on the query and history. |
stream_chat |
Conducts a streaming chat interaction for continuous conversations. |
stream_generate |
Generates text in a streaming fashion based on input ids and generation configuration. |
quantize |
Quantizes the model with a specified number of bits. |
For a detailed understanding of the class functionality and methods, refer to the specific method descriptions.
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMForConditionalGeneration.__init__(config)
¶
Initializes the ChatGLMForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The object instance itself.
|
config |
An instance of ChatGLMConfig containing configuration parameters for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the config parameter is not of type ChatGLMConfig. |
ValueError
|
If the config parameter is missing required attributes. |
AttributeError
|
If the config object does not have certain expected attributes. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMForConditionalGeneration.chat(tokenizer, query, history=None, max_length=2048, num_beams=1, do_sample=True, top_p=0.7, temperature=0.95, logits_processor=None, **kwargs)
¶
This method 'chat' is defined in the class 'ChatGLMForConditionalGeneration' and is used for generating a response to a given query using a conditional generation model. It takes the following parameters:
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
tokenizer |
An instance of a tokenizer that will be used to encode the prompt and decode the generated response.
|
query |
The input query for which a response needs to be generated.
TYPE:
|
history |
A list of tuples containing the previous queries and their corresponding responses. Defaults to None.
TYPE:
|
max_length |
The maximum length of the generated response. Defaults to 2048.
TYPE:
|
num_beams |
Number of beams for beam search. Defaults to 1.
TYPE:
|
do_sample |
Flag indicating whether to use sampling for generating the response. Defaults to True.
TYPE:
|
top_p |
The nucleus sampling top probability. Defaults to 0.7.
TYPE:
|
temperature |
The temperature parameter for sampling. Defaults to 0.95.
TYPE:
|
logits_processor |
An object for processing the logits. Defaults to None.
TYPE:
|
**kwargs |
Additional keyword arguments for model generation.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None
|
This method does not have a specific return value, but it generates a response to the input query and updates the history of queries and responses. |
RAISES | DESCRIPTION |
---|---|
None
|
This method does not explicitly raise any exceptions. However, the behavior of the method may be influenced by exceptions raised by the tokenizer or the conditional generation model used within the method. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMForConditionalGeneration.forward(input_ids=None, position_ids=None, attention_mask=None, past_key_values=None, inputs_embeds=None, labels=None, use_cache=None, output_attentions=None, output_hidden_states=None, return_dict=None)
¶
Constructs the ChatGLMForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMForConditionalGeneration class. |
input_ids |
The input tensor of shape (batch_size, sequence_length) containing the input IDs.
TYPE:
|
position_ids |
The input tensor of shape (batch_size, sequence_length) containing the position IDs.
TYPE:
|
attention_mask |
The input tensor of shape (batch_size, sequence_length) containing the attention mask.
TYPE:
|
past_key_values |
The input tensor of shape (batch_size, sequence_length) containing the past key values.
TYPE:
|
inputs_embeds |
The input tensor of shape (batch_size, sequence_length, embedding_size) containing the embedded inputs.
TYPE:
|
labels |
The input tensor of shape (batch_size, sequence_length) containing the labels.
TYPE:
|
use_cache |
Whether to use cache or not. If not provided, defaults to the value specified in the model's configuration.
TYPE:
|
output_attentions |
Whether to output attentions or not.
TYPE:
|
output_hidden_states |
Whether to output hidden states or not.
TYPE:
|
return_dict |
Whether to return a dictionary or not. If not provided, defaults to the value specified in the model's configuration.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMForConditionalGeneration.get_output_embeddings()
¶
Get the output embeddings for the ChatGLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMForConditionalGeneration class.
|
RETURNS | DESCRIPTION |
---|---|
The output embeddings for the language model head. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMForConditionalGeneration.prepare_inputs_for_generation(input_ids, past=None, past_key_values=None, attention_mask=None, position_ids=None, **kwargs)
¶
This method prepares inputs for generation in the ChatGLMForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMForConditionalGeneration class. |
input_ids |
The input tensor containing the token IDs for the model input.
TYPE:
|
past |
Optional tensor containing the past states for autoregressive generation.
TYPE:
|
past_key_values |
Optional tensor containing past key values for efficient decoding.
TYPE:
|
attention_mask |
Optional tensor specifying which elements in the input should be attended to.
TYPE:
|
position_ids |
Optional tensor specifying the position IDs for input tokens.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the prepared inputs for generation including 'input_ids', 'past_key_values', 'position_ids', and 'attention_mask'.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input arguments are of incorrect types. |
ValueError
|
If there are issues with the input data or configuration. |
IndexError
|
If there are indexing errors while processing the input data. |
Warning
|
If there are warnings related to the attention mask data type. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMForConditionalGeneration.process_response(response)
¶
Processes the response received from the model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMForConditionalGeneration class. |
response |
The response received from the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMForConditionalGeneration.quantize(bits, **kwargs)
¶
Perform quantization on the input data.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLMForConditionalGeneration class. |
bits |
The number of bits to quantize the data to. Must be a positive integer.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMForConditionalGeneration.set_output_embeddings(new_embeddings)
¶
Method to set new output embeddings for the ChatGLMForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMForConditionalGeneration class. |
new_embeddings |
The new output embeddings to be set for the model. This can be of any type.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMForConditionalGeneration.stream_chat(tokenizer, query, history=None, max_length=2048, do_sample=True, top_p=0.7, temperature=0.95, logits_processor=None, **kwargs)
¶
Stream chat method for generating responses based on a given query and history.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLMForConditionalGeneration class. |
tokenizer |
The tokenizer used for tokenizing the input text.
|
query |
The query string for which a response is generated.
TYPE:
|
history |
A list of tuples containing the previous queries and their responses. Defaults to None.
TYPE:
|
max_length |
The maximum length of the generated response. Defaults to 2048.
TYPE:
|
do_sample |
Whether to use sampling for generating response. Defaults to True.
TYPE:
|
top_p |
The cumulative probability threshold for top-p sampling. Defaults to 0.7.
TYPE:
|
temperature |
The temperature value used for sampling. Defaults to 0.95.
TYPE:
|
logits_processor |
An object used for processing logits during response generation. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 |
|
mindnlp.transformers.models.chatglm.modeling_chatglm.ChatGLMForConditionalGeneration.stream_generate(input_ids, generation_config=None, logits_processor=None, stopping_criteria=None, prefix_allowed_tokens_fn=None, **kwargs)
¶
Generates text using the ChatGLM model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMForConditionalGeneration class. |
input_ids |
The input tensor containing the tokenized input sequence.
TYPE:
|
generation_config |
The configuration for text generation. Defaults to None.
TYPE:
|
logits_processor |
The processor for modifying the logits. Defaults to None.
TYPE:
|
stopping_criteria |
The criteria for stopping the generation. Defaults to None.
TYPE:
|
prefix_allowed_tokens_fn |
A function that returns the list of allowed tokens for each prefix. Defaults to None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
RAISES | DESCRIPTION |
---|---|
UserWarning
|
If both |
UserWarning
|
If the input length exceeds the |
Other exceptions
|
Any other exceptions that may occur during the execution of the method. |
Source code in mindnlp/transformers/models/chatglm/modeling_chatglm.py
1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 |
|
mindnlp.transformers.models.chatglm.configuration_chatglm.ChatGLMConfig
¶
Bases: PretrainedConfig
This is the configuration class to store the configuration of a [~ChatGLMModel
].
It is used to instantiate an ChatGLM model according to the specified arguments, defining the model
architecture. Instantiating a configuration with the defaults will yield a similar configuration to that of
the ChatGLM-6B THUDM/ChatGLM-6B architecture.
Configuration objects inherit from [PretrainedConfig
] and can be used
to control the model outputs. Read the documentation from [PretrainedConfig
]
for more information.
PARAMETER | DESCRIPTION |
---|---|
vocab_size |
Vocabulary size of the ChatGLM-6B model. Defines the number of different tokens that can be represented by the
TYPE:
|
hidden_size |
Dimension of the encoder layers and the pooler layer.
TYPE:
|
num_hidden_layers |
Number of hidden layers in the Transformer encoder.
TYPE:
|
num_attention_heads |
Number of attention heads for each attention layer in the Transformer encoder.
TYPE:
|
inner_hidden_size |
Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
TYPE:
|
max_sequence_length |
The maximum sequence length that this model might ever be used with. Typically set this to something large just in case (e.g., 512 or 1024 or 2048).
TYPE:
|
layernorm_epsilon |
The epsilon used by the layer normalization layers.
TYPE:
|
use_cache |
Whether the model should return the last key/values attentions (not used by all models).
TYPE:
|
Example
>>> from configuration_chatglm import ChatGLMConfig
>>> from modeling_chatglm import ChatGLMModel
...
>>> # Initializing a ChatGLM-6B THUDM/ChatGLM-6B style configuration
>>> configuration = ChatGLMConfig()
...
>>> # Initializing a model from the THUDM/ChatGLM-6B style configuration
>>> model = ChatGLMModel(configuration)
...
>>> # Accessing the model configuration
>>> configuration = model.config
Source code in mindnlp/transformers/models/chatglm/configuration_chatglm.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
mindnlp.transformers.models.chatglm.configuration_chatglm.ChatGLMConfig.__init__(vocab_size=150528, hidden_size=4096, num_layers=28, num_attention_heads=32, layernorm_epsilon=1e-05, use_cache=False, bos_token_id=150004, eos_token_id=150005, mask_token_id=150000, gmask_token_id=150001, pad_token_id=0, max_sequence_length=2048, inner_hidden_size=16384, position_encoding_2d=True, quantization_bit=0, pre_seq_len=None, prefix_projection=False, **kwargs)
¶
Initializes a ChatGLMConfig object with the specified configuration parameters.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMConfig class.
TYPE:
|
vocab_size |
The size of the vocabulary. Default is 150528.
TYPE:
|
hidden_size |
The size of the hidden layers. Default is 4096.
TYPE:
|
num_layers |
The number of layers in the model. Default is 28.
TYPE:
|
num_attention_heads |
The number of attention heads. Default is 32.
TYPE:
|
layernorm_epsilon |
The epsilon value for layer normalization. Default is 1e-05.
TYPE:
|
use_cache |
Whether to use cache during inference. Default is False.
TYPE:
|
bos_token_id |
The ID of the beginning of sequence token. Default is 150004.
TYPE:
|
eos_token_id |
The ID of the end of sequence token. Default is 150005.
TYPE:
|
mask_token_id |
The ID of the mask token. Default is 150000.
TYPE:
|
gmask_token_id |
The ID of the global mask token. Default is 150001.
TYPE:
|
pad_token_id |
The ID of the padding token. Default is 0.
TYPE:
|
max_sequence_length |
The maximum sequence length allowed. Default is 2048.
TYPE:
|
inner_hidden_size |
The size of inner hidden layers. Default is 16384.
TYPE:
|
position_encoding_2d |
Whether to use 2D position encoding. Default is True.
TYPE:
|
quantization_bit |
The number of bits for quantization. Default is 0.
TYPE:
|
pre_seq_len |
The length of the preceding sequence. Default is None.
TYPE:
|
prefix_projection |
Whether to use prefix projection. Default is False.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/chatglm/configuration_chatglm.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
mindnlp.transformers.models.chatglm.tokenization_chatglm.ChatGLMTokenizer
¶
Bases: PreTrainedTokenizer
Construct a ChatGLM tokenizer. Based on byte-level Byte-Pair-Encoding.
PARAMETER | DESCRIPTION |
---|---|
vocab_file |
Path to the vocabulary file.
TYPE:
|
Source code in mindnlp/transformers/models/chatglm/tokenization_chatglm.py
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 |
|
mindnlp.transformers.models.chatglm.tokenization_chatglm.ChatGLMTokenizer.end_token_id: Optional[int]
property
¶
RETURNS | DESCRIPTION |
---|---|
Optional[int]
|
|
mindnlp.transformers.models.chatglm.tokenization_chatglm.ChatGLMTokenizer.gmask_token = gmask_token
instance-attribute
¶
Initialisation
mindnlp.transformers.models.chatglm.tokenization_chatglm.ChatGLMTokenizer.gmask_token_id: Optional[int]
property
¶
This method returns the token ID of the gmask token in the ChatGLMTokenizer.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMTokenizer class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Optional[int]
|
Optional[int]: Returns the token ID of the gmask token if it exists, otherwise returns None. |
mindnlp.transformers.models.chatglm.tokenization_chatglm.ChatGLMTokenizer.vocab_size
property
¶
Returns vocab size
mindnlp.transformers.models.chatglm.tokenization_chatglm.ChatGLMTokenizer.__init__(vocab_file, do_lower_case=False, remove_space=False, bos_token='<sop>', eos_token='<eop>', end_token='</s>', mask_token='[MASK]', gmask_token='[gMASK]', padding_side='left', pad_token='<pad>', unk_token='<unk>', num_image_tokens=20000, **kwargs)
¶
Initializes a ChatGLMTokenizer object.
PARAMETER | DESCRIPTION |
---|---|
vocab_file |
The file path to the vocabulary file.
TYPE:
|
do_lower_case |
Flag indicating whether to convert all tokens to lowercase. Defaults to False.
TYPE:
|
remove_space |
Flag indicating whether to remove spaces from tokens. Defaults to False.
TYPE:
|
bos_token |
The beginning of sentence token. Defaults to '
TYPE:
|
eos_token |
The end of sentence token. Defaults to '
TYPE:
|
end_token |
The end token. Defaults to ''.
TYPE:
|
mask_token |
The mask token. Defaults to '[MASK]'.
TYPE:
|
gmask_token |
The global mask token. Defaults to '[gMASK]'.
TYPE:
|
padding_side |
The side to pad tokens on. Defaults to 'left'.
TYPE:
|
pad_token |
The padding token. Defaults to '
TYPE:
|
unk_token |
The unknown token. Defaults to '
TYPE:
|
num_image_tokens |
The number of image tokens. Defaults to 20000.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
None
|
None. |
RAISES | DESCRIPTION |
---|---|
None
|
This method does not raise any exceptions. |
Source code in mindnlp/transformers/models/chatglm/tokenization_chatglm.py
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 |
|
mindnlp.transformers.models.chatglm.tokenization_chatglm.ChatGLMTokenizer.build_inputs_with_special_tokens(token_ids_0, token_ids_1=None)
¶
Build model inputs from a sequence or a pair of sequence for sequence classification tasks by concatenating and adding special tokens. A BERT sequence has the following format:
- single sequence:
[CLS] X [SEP]
- pair of sequences:
[CLS] A [SEP] B [SEP]
PARAMETER | DESCRIPTION |
---|---|
token_ids_0 |
List of IDs to which the special tokens will be added.
TYPE:
|
token_ids_1 |
Optional second list of IDs for sequence pairs.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
List[int]
|
|
Source code in mindnlp/transformers/models/chatglm/tokenization_chatglm.py
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
|
mindnlp.transformers.models.chatglm.tokenization_chatglm.ChatGLMTokenizer.convert_tokens_to_string(tokens)
¶
Converts a list of tokens into a single string representation.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the ChatGLMTokenizer class.
TYPE:
|
tokens |
A list of tokens to be converted into a string representation.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The string representation of the given list of tokens.
TYPE:
|
Note
- The tokens should be generated using the sp_tokenizer of the ChatGLMTokenizer instance.
- The resulting string may contain whitespace and punctuation marks based on the original tokenization.
Example
>>> tokenizer = ChatGLMTokenizer()
>>> tokens = ['Hello', ',', 'how', 'are', 'you', '?']
>>> string_representation = tokenizer.convert_tokens_to_string(tokens)
Source code in mindnlp/transformers/models/chatglm/tokenization_chatglm.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 |
|
mindnlp.transformers.models.chatglm.tokenization_chatglm.ChatGLMTokenizer.get_vocab()
¶
Returns vocab as a dict
Source code in mindnlp/transformers/models/chatglm/tokenization_chatglm.py
595 596 597 598 599 |
|
mindnlp.transformers.models.chatglm.tokenization_chatglm.ChatGLMTokenizer.preprocess_text(inputs)
¶
preprocess_text method in the ChatGLMTokenizer class preprocesses the input text based on the specified configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the ChatGLMTokenizer class.
TYPE:
|
inputs |
The input text to be preprocessed.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str
|
The preprocessed text based on the specified configuration.
|
Source code in mindnlp/transformers/models/chatglm/tokenization_chatglm.py
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
|
mindnlp.transformers.models.chatglm.tokenization_chatglm.ChatGLMTokenizer.save_vocabulary(save_directory, filename_prefix=None)
¶
Save the vocabulary and special tokens file to a directory.
PARAMETER | DESCRIPTION |
---|---|
save_directory |
The directory in which to save the vocabulary.
TYPE:
|
filename_prefix |
An optional prefix to add to the named of the saved files.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
|
Source code in mindnlp/transformers/models/chatglm/tokenization_chatglm.py
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMModel
¶
Bases: MSChatGLMPreTrainedModel
The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer of cross-attention is added between the self-attention layers, following the architecture described in Attention is all you need by Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser and Illia Polosukhin.
To behave as an decoder the model needs to be initialized with the
is_decoder
argument of the configuration set to True
.
To be used in a Seq2Seq model, the model needs to initialized with both is_decoder
argument and add_cross_attention
set to True
; an
encoder_hidden_states
is then expected as an input to the forward pass.
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMModel.__init__(config)
¶
Initializes an instance of the MSChatGLMModel class with the provided configuration.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MSChatGLMModel class.
|
config |
The configuration for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None |
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMModel.forward(input_ids=None, position_ids=None, attention_mask=None, past_key_values=None, inputs_embeds=None)
¶
Constructs the MSChatGLMModel.
This method is used to forward the MSChatGLMModel. It takes in several parameters and returns a tuple of tensors.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MSChatGLMModel class.
TYPE:
|
input_ids |
The input tensor representing the tokenized input sequences. Default is None.
TYPE:
|
position_ids |
The input tensor representing the position ids of the tokens. Default is None.
TYPE:
|
attention_mask |
The input tensor representing the attention mask. Default is None.
TYPE:
|
past_key_values |
The input tensor representing the past key values. Default is None.
TYPE:
|
inputs_embeds |
The input tensor representing the embedded input sequences. Default is None.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Tuple[Tensor, ...]
|
Tuple[mindspore.Tensor, ...]: A tuple containing the hidden states, presents, all hidden states, and all self attentions. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If both input_ids and inputs_embeds are specified. |
ValueError
|
If neither input_ids nor inputs_embeds are specified. |
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMModel.get_input_embeddings()
¶
Retrieve the input embeddings for the MSChatGLMModel.
PARAMETER | DESCRIPTION |
---|---|
self |
An instance of the MSChatGLMModel class.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
844 845 846 847 848 849 850 851 852 853 854 855 856 857 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMModel.get_prompt(batch_size, dtype=mindspore.float16)
¶
get prompt.
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMModel.set_input_embeddings(new_embeddings)
¶
Sets the input embeddings for the MSChatGLMModel.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MSChatGLMModel class.
TYPE:
|
new_embeddings |
The new embeddings to be set as input. It should be a tensor object representing the word embeddings.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Note
The input embeddings are used for representing words in the MSChatGLMModel. By setting new embeddings, the model can be fine-tuned or customized to use different word representations.
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMPreTrainedModel
¶
Bases: PreTrainedModel
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained models.
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMPreTrainedModel.get_masks(input_ids)
¶
get masks
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
707 708 709 710 711 712 713 714 715 716 717 718 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMPreTrainedModel.get_position_ids(input_ids, mask_positions, use_gmasks=None)
¶
get position ids
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMForConditionalGeneration
¶
Bases: MSChatGLMPreTrainedModel
MSChatGLMForConditionalGeneration
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMForConditionalGeneration.__init__(config)
¶
Initializes an instance of the MSChatGLMForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MSChatGLMForConditionalGeneration class.
|
config |
An object of type ChatGLMConfig containing configuration parameters for the model.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMForConditionalGeneration.chat(tokenizer, query, history=None, max_length=2048, num_beams=1, do_sample=True, top_p=0.7, temperature=0.95, logits_processor=None, **kwargs)
¶
chat.
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMForConditionalGeneration.forward(input_ids=None, position_ids=None, attention_mask=None, past_key_values=None, **kwargs)
¶
Constructs the MSChatGLMForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MSChatGLMForConditionalGeneration class. |
input_ids |
The input tensor containing the tokenized input sequence. Default is None.
TYPE:
|
position_ids |
The tensor containing the position indices for each token in the input sequence. Default is None.
TYPE:
|
attention_mask |
The mask tensor indicating which elements in the input sequence should be attended to. Default is None.
TYPE:
|
past_key_values |
The tuple of tensors containing the key-value pairs from the previous attention pass. Default is None.
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the following keys:
|
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMForConditionalGeneration.get_output_embeddings()
¶
Returns the output embeddings of the MSChatGLMForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MSChatGLMForConditionalGeneration class.
|
RETURNS | DESCRIPTION |
---|---|
returns the output embeddings of the model as a tensor. |
This method retrieves the output embeddings of the MSChatGLMForConditionalGeneration model. The output embeddings are the final representations of the input tokens after being processed by the model's language model head. The embeddings are returned as a tensor.
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMForConditionalGeneration.prepare_inputs_for_generation(input_ids, past=None, past_key_values=None, attention_mask=None, position_ids=None, **kwargs)
¶
This method prepares inputs for generation in the MSChatGLMForConditionalGeneration class.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the class.
|
input_ids |
The input tensor containing token ids.
TYPE:
|
past |
The past state tensor (default is None).
TYPE:
|
past_key_values |
The past key values tensor (default is None).
TYPE:
|
attention_mask |
The attention mask tensor (default is None).
TYPE:
|
position_ids |
The position ids tensor (default is None).
TYPE:
|
**kwargs |
Additional keyword arguments.
DEFAULT:
|
RETURNS | DESCRIPTION |
---|---|
dict
|
A dictionary containing the prepared inputs for generation including 'input_ids', 'past_key_values', 'position_ids', and 'attention_mask'.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TypeError
|
If the input arguments are not of the expected types. |
ValueError
|
If there are issues with the input data or configuration. |
IndexError
|
If there are index out of bounds errors during processing. |
Warning
|
If there are issues with the dtype of attention mask. |
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMForConditionalGeneration.process_response(response)
¶
process_response
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMForConditionalGeneration.quantize(bits, empty_init=False, **kwargs)
¶
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
1487 1488 |
|
mindnlp.transformers.models.chatglm.modeling_graph_chatglm.MSChatGLMForConditionalGeneration.set_output_embeddings(new_embeddings)
¶
Set the output embeddings for the MSChatGLMForConditionalGeneration model.
PARAMETER | DESCRIPTION |
---|---|
self |
The instance of the MSChatGLMForConditionalGeneration class. |
new_embeddings |
The new embeddings to be set as the output embeddings for the model. It can be of any valid type.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
None. |
Source code in mindnlp/transformers/models/chatglm/modeling_graph_chatglm.py
1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 |
|