sasha-smirnov commited on
Commit
0231c41
·
verified ·
1 Parent(s): c7fdffd

Initial publish via td-embeddings

Browse files
README.md ADDED
@@ -0,0 +1,186 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - code
5
+ library_name: transformers
6
+ pipeline_tag: feature-extraction
7
+ base_model: codesage/codesage-small
8
+ tags:
9
+ - onnx
10
+ - teradata
11
+ - byom
12
+ - embeddings
13
+ - feature-extraction
14
+ ---
15
+
16
+
17
+
18
+ > Read the disclaimer below before using this model.
19
+
20
+ ----
21
+
22
+ # codesage-small -- ONNX for Teradata BYOM
23
+
24
+ This repository hosts an **ONNX-converted** version of the upstream
25
+ model [`codesage/codesage-small`](https://huggingface.co/codesage/codesage-small),
26
+ packaged for the Teradata Vantage `mldb.ONNXEmbeddings` BYOM
27
+ function. It is **not** the original PyTorch model -- only the
28
+ inference graph and tokenizer needed for in-database embedding
29
+ generation.
30
+
31
+ What's different from upstream:
32
+
33
+ - **Format**: ONNX (opset 14, IR version 8 -- BYOM 6+ compatible),
34
+ produced from the upstream weights with architecture-aware
35
+ post-processing baked in.
36
+ - **Precision**: dynamic int8 quantization. See the variants table
37
+ below for what is shipped for this model.
38
+ - **Pooling and post-processing**: this graph emits the raw
39
+ `sentence_embedding` tensor. Pooling rule is
40
+ **mean**.
41
+ - **Verification**: every variant's cosine fidelity vs. the
42
+ upstream PyTorch reference is recorded on a fixed
43
+ CodeSearchNet sample. Numbers may not generalize
44
+ to your data.
45
+
46
+ ## Model details
47
+
48
+ | | |
49
+ |---|---|
50
+ | Upstream repo | [`codesage/codesage-small`](https://huggingface.co/codesage/codesage-small) |
51
+ | Architecture | `CodeSage` (encoder) |
52
+ | Parameters | 128,010,240 |
53
+ | Output dimensions | 1024 |
54
+ | Pooling | `mean` |
55
+ | Instruction prefix | no |
56
+ | Max input tokens (advertised) | 2048 |
57
+ | Languages | 9 |
58
+ | License | apache-2.0 |
59
+ | ONNX opset | 14 |
60
+ | ONNX IR version | 8 (BYOM 6+ compatible) |
61
+
62
+ <details>
63
+ <summary>Full language list (9)</summary>
64
+
65
+ - `c`
66
+ - `c-sharp`
67
+ - `go`
68
+ - `java`
69
+ - `javascript`
70
+ - `typescript`
71
+ - `php`
72
+ - `python`
73
+ - `ruby`
74
+
75
+ </details>
76
+
77
+ ## Quantization variants
78
+
79
+ This repository ships the following variants. Quality numbers are
80
+ measured against the upstream PyTorch reference on a fixed
81
+ CodeSearchNet sample. The **Size** column is the
82
+ on-disk size of the ONNX weight file in megabytes (MB, 10^6 bytes).
83
+
84
+ | Variant | Size (MB) | p50 cosine | R@1 |
85
+ |---|---|---|---|
86
+ | `fp32` | 512.2 | 1.000000 | — |
87
+
88
+
89
+ How to read the quality columns:
90
+
91
+ - **p50 cosine** is the median cosine similarity between this
92
+ variant's embeddings and the fp32 ONNX reference, computed over
93
+ a fixed evaluation set. Higher means closer to the unquantized
94
+ model; **1.0** is identical.
95
+ - **R@1** is top-1 retrieval consistency: if you use this variant
96
+ as a search index, R@1 is the fraction of queries that get the
97
+ same nearest neighbor as the fp32 reference would. Higher is
98
+ better.
99
+
100
+ Notes:
101
+ - **fp32**: full-precision reference. Useful for an accuracy ceiling,
102
+ but BYOM users almost always want one of the int8 variants for
103
+ in-database scoring -- they are 3-4x smaller and load much faster.
104
+
105
+ ## Quickstart: using this model with Teradata BYOM
106
+
107
+ Requires Teradata Vantage with **BYOM 6+** (`mldb.ONNXEmbeddings`).
108
+
109
+ ```python
110
+ import getpass
111
+ import teradataml as tdml
112
+ from huggingface_hub import hf_hub_download
113
+
114
+ repo_id = "Teradata/codesage-small"
115
+ model_id = "codesage-small" # arbitrary, used as the BYOM model_id
116
+ onnx_file = "onnx/model-fp32.onnx"
117
+
118
+ # 1. Download the ONNX + tokenizer for the chosen variant.
119
+ hf_hub_download(repo_id=repo_id, filename=onnx_file, local_dir="./")
120
+ hf_hub_download(repo_id=repo_id, filename="tokenizer.json", local_dir="./")
121
+
122
+ # 2. Connect to Vantage.
123
+ tdml.create_context(
124
+ host=input("host: "),
125
+ username=input("user: "),
126
+ password=getpass.getpass("password: "),
127
+ )
128
+
129
+ # 3. Load model + tokenizer into BYOM tables (one-time per model_id).
130
+ tdml.save_byom(model_id=model_id, model_file=onnx_file,
131
+ table_name="embeddings_models")
132
+ tdml.save_byom(model_id=model_id, model_file="tokenizer.json",
133
+ table_name="embeddings_tokenizers")
134
+ ```
135
+
136
+ Then call `mldb.ONNXEmbeddings` against an input table whose
137
+ `txt` column carries the strings to embed:
138
+
139
+ ```sql
140
+ SELECT *
141
+ FROM mldb.ONNXEmbeddings(
142
+ ON (SELECT id, txt FROM your_input_table) AS InputTable
143
+ ON (SELECT model_id, model FROM embeddings_models
144
+ WHERE model_id = 'codesage-small') AS ModelTable DIMENSION
145
+ ON (SELECT model_id, tokenizer FROM embeddings_tokenizers
146
+ WHERE model_id = 'codesage-small') AS TokenizerTable DIMENSION
147
+ USING
148
+ Accumulate('id')
149
+ ModelOutputTensor('sentence_embedding')
150
+ OutputFormat('FLOAT32(1024)')
151
+ OverwriteCachedModel('*')
152
+ ) AS t
153
+ ORDER BY id;
154
+ ```
155
+
156
+ Pooling rule **`mean`** is applied **inside** the converted
157
+ ONNX graph -- the output tensor named above already contains the
158
+ pooled, post-processed embedding vector.
159
+
160
+ ## Original model attribution
161
+
162
+ The original weights and training methodology belong to
163
+ **the CodeSage authors**. Please cite their work, not this
164
+ repository, in academic contexts. The canonical upstream model card
165
+ is at
166
+ [`codesage/codesage-small`](https://huggingface.co/codesage/codesage-small);
167
+ refer to it for benchmarks, training details, intended use, and
168
+ citation information.
169
+
170
+ ## Reporting issues
171
+
172
+ For ONNX-conversion or BYOM-compatibility issues specific to this
173
+ Teradata-converted artifact, please open a **Discussion** on this
174
+ model's Hugging Face page. Questions about the underlying model
175
+ quality, training, or intended use should go to the upstream
176
+ maintainer's model card.
177
+
178
+ ----
179
+
180
+ DISCLAIMER: The content herein ("Content") is provided "AS IS" and is not covered by any Teradata Operations, Inc. and its affiliates ("Teradata") agreements. Its listing here does not constitute certification or endorsement by Teradata.
181
+
182
+ To the extent any of the Content contains or is related to any artificial intelligence ("AI") or other language learning models ("Models") that interoperate with the products and services of Teradata, by accessing, bringing, deploying or using such Models, you acknowledge and agree that you are solely responsible for ensuring compliance with all applicable laws, regulations, and restrictions governing the use, deployment, and distribution of AI technologies. This includes, but is not limited to, AI Diffusion Rules, European Union AI Act, AI-related laws and regulations, privacy laws, export controls, and financial or sector-specific regulations.
183
+
184
+ While Teradata may provide support, guidance, or assistance in the deployment or implementation of Models to interoperate with Teradata's products and/or services, you remain fully responsible for ensuring that your Models, data, and applications comply with all relevant legal and regulatory obligations. Our assistance does not constitute legal or regulatory approval, and Teradata disclaims any liability arising from non-compliance with applicable laws.
185
+
186
+ You must determine the suitability of the Models for any purpose. Given the probabilistic nature of machine learning and modeling, the use of the Models may in some situations result in incorrect output that does not accurately reflect the action generated. You should evaluate the accuracy of any output as appropriate for your use case, including by using human review of the output.
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "codesage/codesage-small",
3
+ "architectures": [
4
+ "CodeSage"
5
+ ],
6
+ "auto_map": {
7
+ "AutoConfig": "config_codesage.CodeSageConfig",
8
+ "AutoTokenizer": "tokenization_codesage.CodeSageTokenizer",
9
+ "AutoModel": "modeling_codesage.CodeSageModel",
10
+ "AutoModelForMaskedLM": "modeling_codesage.CodeSageForMaskedLM",
11
+ "AutoModelForSequenceClassification": "modeling_codesage.CodeSageForSequenceClassification"
12
+ },
13
+ "activation_function": "gelu_new",
14
+ "attention_dropout_prob": 0.1,
15
+ "embedding_dropout_prob": 0.1,
16
+ "initializer_range": 0.02,
17
+ "layer_norm_epsilon": 1e-05,
18
+ "hidden_size": 1024,
19
+ "num_attention_heads": 8,
20
+ "num_hidden_layers": 6,
21
+ "intermediate_size": 4096,
22
+ "max_position_embeddings": 2048,
23
+ "residual_dropout_prob": 0.1,
24
+ "vocab_size": 49154
25
+ }
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 50256,
4
+ "eos_token_id": 50256,
5
+ "transformers_version": "4.28.1"
6
+ }
onnx/model-fp32.onnx ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:598d2277f44d871de5c1baa9f553e5541e3b8cfe72385bd2535fa954ca4f06c0
3
+ size 512235748
special_tokens_map.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|endoftext|>",
4
+ "<fim_prefix>",
5
+ "<fim_middle>",
6
+ "<fim_suffix>",
7
+ "<fim_pad>",
8
+ "<filename>",
9
+ "<gh_stars>",
10
+ "<issue_start>",
11
+ "<issue_comment>",
12
+ "<issue_closed>",
13
+ "<jupyter_start>",
14
+ "<jupyter_text>",
15
+ "<jupyter_code>",
16
+ "<jupyter_output>",
17
+ "<empty_output>",
18
+ "<commit_before>",
19
+ "<commit_msg>",
20
+ "<commit_after>",
21
+ "<reponame>"
22
+ ],
23
+ "bos_token": "<|endoftext|>",
24
+ "eos_token": "<|endoftext|>",
25
+ "mask_token": "<mask>",
26
+ "pad_token": "<pad>",
27
+ "unk_token": "<|endoftext|>"
28
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "additional_special_tokens": [
4
+ "<|endoftext|>",
5
+ "<fim_prefix>",
6
+ "<fim_middle>",
7
+ "<fim_suffix>",
8
+ "<fim_pad>",
9
+ "<filename>",
10
+ "<gh_stars>",
11
+ "<issue_start>",
12
+ "<issue_comment>",
13
+ "<issue_closed>",
14
+ "<jupyter_start>",
15
+ "<jupyter_text>",
16
+ "<jupyter_code>",
17
+ "<jupyter_output>",
18
+ "<empty_output>",
19
+ "<commit_before>",
20
+ "<commit_msg>",
21
+ "<commit_after>",
22
+ "<reponame>"
23
+ ],
24
+ "bos_token": "<|endoftext|>",
25
+ "clean_up_tokenization_spaces": true,
26
+ "eos_token": "<|endoftext|>",
27
+ "add_eos_token": true,
28
+ "model_max_length": 1000000000000000019884624838656,
29
+ "unk_token": "<|endoftext|>",
30
+ "vocab_size": 49152,
31
+ "tokenizer_class": "CodeSageTokenizer",
32
+ "auto_map": {
33
+ "AutoTokenizer": ["tokenization_codesage.CodeSageTokenizer", null]
34
+ }
35
+ }