-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Add Annotation to Stored Triples #10410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nv-rliu
wants to merge
22
commits into
pyg-team:latest-txt2kg
Choose a base branch
from
nv-rliu:add-annotation-to-triples
base: latest-txt2kg
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
581c864
Add support for storing model name alongside triples
nv-rliu b3353f6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2dfde6c
Add messaging
nv-rliu df3e8b1
Merge branch 'add-annotation-to-triples' of https://github.com/nv-rli…
nv-rliu 850b41f
update
nv-rliu b3a93d4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] a5e3d37
Merge branch 'latest-txt2kg' into add-annotation-to-triples
nv-rliu baf737e
Fix style
nv-rliu 796fa3f
Merge branch 'add-annotation-to-triples' of https://github.com/nv-rli…
nv-rliu 25a5e1d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b64f17e
Add support for storing model and timestamp in filename
nv-rliu 6ca48d3
Merge branch 'add-annotation-to-triples' of https://github.com/nv-rli…
nv-rliu ad2644f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4270ab8
Revert
nv-rliu 1c3369e
Revert
nv-rliu a7abdd4
Merge branch 'add-annotation-to-triples' of https://github.com/nv-rli…
nv-rliu 54b6c8c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 389835e
Revert README
nv-rliu 3f72d19
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b132bd7
Merge branch 'latest-txt2kg' into add-annotation-to-triples
puririshi98 b430610
Merge branch 'latest-txt2kg' into add-annotation-to-triples
puririshi98 434827e
Merge branch 'latest-txt2kg' into add-annotation-to-triples
puririshi98 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -322,8 +322,15 @@ def index_kg(args, context_docs): | |
checkpoint_path = os.path.join(args.dataset, "checkpoint_kg.pt") | ||
if os.path.exists(checkpoint_path): | ||
print("Restoring KG from checkpoint...") | ||
saved_relevant_triples = torch.load(checkpoint_path, | ||
weights_only=False) | ||
checkpoint_data = torch.load(checkpoint_path) | ||
|
||
# check to see if triples generation are using the correct model | ||
if args.NV_NIM_MODEL.split('/')[-1] != checkpoint_data['model']: | ||
raise RuntimeError( | ||
"Error: The stored triples were generated using a different model" | ||
) | ||
|
||
saved_relevant_triples = checkpoint_data['triples'] | ||
kg_maker.relevant_triples = saved_relevant_triples | ||
kg_maker.doc_id_counter = len(saved_relevant_triples) | ||
initial_tqdm_count = kg_maker.doc_id_counter | ||
|
@@ -346,7 +353,10 @@ def index_kg(args, context_docs): | |
for triple_set in relevant_triples.values())) | ||
triples = list(dict.fromkeys(triples)) | ||
raw_triples_path = os.path.join(args.dataset, "raw_triples.pt") | ||
torch.save(triples, raw_triples_path) | ||
torch.save({ | ||
"model": kg_maker.get_model_name(), | ||
"triples": triples, | ||
}, raw_triples_path) | ||
if os.path.exists(checkpoint_path): | ||
os.remove(checkpoint_path) | ||
return triples | ||
|
@@ -409,12 +419,18 @@ def make_dataset(args): | |
triples = [] | ||
raw_triples_path = os.path.join(args.dataset, "raw_triples.pt") | ||
if os.path.exists(raw_triples_path): | ||
triples = torch.load(raw_triples_path, weights_only=False) | ||
saved_data = torch.load(raw_triples_path) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. plz save/load w format {llm-name}{datetime}raw_triples.pt There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed format |
||
if args.NV_NIM_MODEL.split('/')[-1] != saved_data['model']: | ||
raise RuntimeError( | ||
"Error: The stored triples were generated using a different model" | ||
) | ||
|
||
print(f" -> Saved triples generated with: {saved_data['model']}") | ||
triples = saved_data['triples'] | ||
else: | ||
triples = index_kg(args, context_docs) | ||
|
||
print("Number of triples in our GraphDB =", len(triples)) | ||
|
||
device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | ||
|
||
# creating the embedding model | ||
|
@@ -746,7 +762,6 @@ def eval(question: str, pred: str, correct_answer: str): | |
data_lists = update_data_lists(args, data_lists) | ||
else: | ||
data_lists = make_dataset(args) | ||
|
||
batch_size = args.batch_size | ||
eval_batch_size = args.eval_batch_size | ||
train_loader = DataLoader(data_lists["train"], batch_size=batch_size, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you remove
weights_only=False
?i think you should leave that arg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought
weights_only
was only useful if we want to extract model weights and biases, aka, tensors. Otherwise, isn't the argument not really useful in this situation? I can add it back if that's incorrectThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK thats the case when you set
True
, here we want to load items that are not Tensors (W&B), so we need to set it toFalse
, otherwise pytorch might complaintThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay. I thought it was okay to not use it since this Data object is never storing weights and biases. I'll add that back in.