Skip to content

Commit 71adbed

Browse files
hallogameboyJyun-Yu Jiang
andauthored
Remove a redundant XMR test; Add weights_only argument for torch.load; (#303)
Bump CodeQL version to v3 Co-authored-by: Jyun-Yu Jiang <[email protected]>
1 parent 7b989e0 commit 71adbed

File tree

6 files changed

+10
-64
lines changed

6 files changed

+10
-64
lines changed

.github/workflows/codeql.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ jobs:
2323

2424
steps:
2525
- name: Checkout repository
26-
uses: actions/checkout@v2
26+
uses: actions/checkout@v3
2727

2828
# Initializes the CodeQL tools for scanning.
2929
- name: Initialize CodeQL
30-
uses: github/codeql-action/init@v2
30+
uses: github/codeql-action/init@v3
3131
with:
3232
languages: ${{ matrix.language }}
3333

3434
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
3535
# If this step fails, then you should remove it and run the build manually (see below)
3636
- name: Autobuild
37-
uses: github/codeql-action/autobuild@v2
37+
uses: github/codeql-action/autobuild@v3
3838

3939
# ℹ️ Command-line programs to run using the OS shell.
4040
# 📚 https://git.io/JvXDl
@@ -48,4 +48,4 @@ jobs:
4848
# make release
4949

5050
- name: Perform CodeQL Analysis
51-
uses: github/codeql-action/analyze@v2
51+
uses: github/codeql-action/analyze@v3

.github/workflows/pytest_aarch64.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ jobs:
66
Ubuntu-Python-Unit-Test:
77
name: Ubuntu 22.04 Python3.10 Unit Tests
88

9-
runs-on: ubuntu-latest
9+
runs-on: ubuntu-22.04-arm
1010

1111
steps:
1212
- uses: actions/checkout@v1

pecos/core/utils/file_util.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#define __FILE_UTIL_H__
1616

1717
#include <algorithm>
18+
#include <cstdint>
1819
#include <fstream>
1920
#include <stdexcept>
2021
#include <string>

pecos/xmc/xtransformer/matcher.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ def load(cls, load_dir):
408408
# load text_model
409409
text_model_dir = os.path.join(load_dir, "text_model")
410410
if os.path.exists(text_model_dir):
411-
text_model = torch.load(text_model_dir)
411+
text_model = torch.load(text_model_dir, weights_only=False)
412412
else:
413413
text_model = None
414414

@@ -1330,7 +1330,7 @@ def train(
13301330
saved_trn_pt = kwargs.get("saved_trn_pt", "")
13311331
if not prob.is_tokenized:
13321332
if saved_trn_pt and os.path.isfile(saved_trn_pt):
1333-
trn_tensors = torch.load(saved_trn_pt)
1333+
trn_tensors = torch.load(saved_trn_pt, weights_only=False)
13341334
LOGGER.info("trn tensors loaded_from {}".format(saved_trn_pt))
13351335
else:
13361336
trn_tensors = matcher.text_to_tensor(
@@ -1345,7 +1345,7 @@ def train(
13451345
if val_prob is not None and not val_prob.is_tokenized:
13461346
saved_val_pt = kwargs.get("saved_val_pt", "")
13471347
if saved_val_pt and os.path.isfile(saved_val_pt):
1348-
val_tensors = torch.load(saved_val_pt)
1348+
val_tensors = torch.load(saved_val_pt, weights_only=False)
13491349
LOGGER.info("val tensors loaded from {}".format(saved_val_pt))
13501350
else:
13511351
val_tensors = matcher.text_to_tensor(

pecos/xmc/xtransformer/module.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ def load(cls, load_dir, shard=0):
454454
nr_shards = cls.get_data_stats(load_dir)["num_shards"]
455455
if shard >= nr_shards:
456456
raise ValueError(f"Loading shard#{shard} where there are only {nr_shards} available")
457-
return torch.load(f"{load_dir}/{shard}")
457+
return torch.load(f"{load_dir}/{shard}", weights_only=False)
458458

459459
@property
460460
def has_ns(self):

test/pecos/xmr/test_reranker.py

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -50,58 +50,3 @@ def test_numr_encoder():
5050
out_feat.numpy(),
5151
abs=0.0,
5252
), f"Enc(inp_feat) != inp_feat, given Enc is identity"
53-
54-
55-
def test_textnumr_encoder():
56-
import torch
57-
from transformers import set_seed
58-
from transformers import AutoConfig, AutoTokenizer
59-
from pecos.xmr.reranker.model import TextNumrEncoderConfig
60-
from pecos.xmr.reranker.model import TextNumrEncoder
61-
62-
enc_list = [
63-
"prajjwal1/bert-tiny",
64-
"sentence-transformers/all-MiniLM-L6-v2",
65-
"intfloat/multilingual-e5-small",
66-
]
67-
ans_list = [
68-
0.007879042997956276,
69-
0.0035168465692549944,
70-
-0.0047034271992743015,
71-
]
72-
set_seed(1234)
73-
74-
for idx, enc_name in enumerate(enc_list):
75-
text_config = AutoConfig.from_pretrained(
76-
enc_name,
77-
hidden_dropout_prob=0.0,
78-
)
79-
textnumr_config = TextNumrEncoderConfig(
80-
text_config=text_config,
81-
numr_config=None,
82-
text_pooling_type="cls",
83-
head_actv_type="identity",
84-
head_dropout_prob=0.0,
85-
head_size_list=[1],
86-
)
87-
textnumr_encoder = TextNumrEncoder(textnumr_config)
88-
linear_layer = textnumr_encoder.head_layers.mlp_layers[0]
89-
linear_layer.bias.data.fill_(0.0)
90-
linear_layer.weight.data.fill_(0.0)
91-
linear_layer.weight.data.fill_diagonal_(1.0)
92-
textnumr_encoder.scorer.bias.data.fill_(0.0)
93-
textnumr_encoder.scorer.weight.data.fill_(1.0)
94-
95-
# obtained from bert-tiny tokenizer("I Like coffee")
96-
tokenizer = AutoTokenizer.from_pretrained(enc_name)
97-
input_dict = tokenizer("I Like coffee", return_tensors="pt")
98-
outputs = textnumr_encoder(**input_dict)
99-
assert outputs.text_emb is not None
100-
assert outputs.numr_emb is None
101-
102-
text_emb = outputs.text_emb
103-
mu = torch.mean(text_emb).item()
104-
assert mu == approx(
105-
ans_list[idx],
106-
abs=1e-3,
107-
), f"mu(text_emb)={mu} != {ans_list[idx]}"

0 commit comments

Comments
 (0)