Skip to content

Improvement of the txt2kg example.#10623

Merged
akihironitta merged 67 commits intopyg-team:masterfrom
drivanov:txt2kg_sigterm
Mar 13, 2026
Merged

Improvement of the txt2kg example.#10623
akihironitta merged 67 commits intopyg-team:masterfrom
drivanov:txt2kg_sigterm

Conversation

@drivanov
Copy link
Contributor

Summary

This PR refactors the multiprocessing logic in torch_geometric.llm.models.txt2kg.py to improve reproducibility and stability.

Key Changes

  • Remove tmp-file IPC

    • Workers now return List[(s, p, o)] directly
    • Eliminates /tmp/outs_for_proc_* files
    • No filesystem side effects
  • Fix spawn-related instability

    • Worker moved to module scope (picklable)
    • Explicit error propagation
    • Prevents silent SIGTERM cascades
  • Ensure deterministic output

    • Global lexicographic sort of triples after aggregation
    • Output stable across runs and worker counts

Result

  • Reproducible KG extraction
  • Cleaner multiprocessing design
  • No temp files
  • Clearer failure modes
  • No API changes.

Change in llm.py eliminates the following warning:

`torch_dtype` is deprecated! Use `dtype` instead!

@codecov
Copy link

codecov bot commented Feb 26, 2026

Codecov Report

❌ Patch coverage is 73.01587% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.92%. Comparing base (c211214) to head (72404fb).
⚠️ Report is 175 commits behind head on master.

Files with missing lines Patch % Lines
torch_geometric/llm/models/llm.py 16.66% 10 Missing ⚠️
torch_geometric/llm/models/txt2kg.py 86.66% 6 Missing ⚠️
torch_geometric/llm/models/g_retriever.py 83.33% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (73.01%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10623      +/-   ##
==========================================
- Coverage   86.11%   85.92%   -0.20%     
==========================================
  Files         496      510      +14     
  Lines       33655    36016    +2361     
==========================================
+ Hits        28981    30945    +1964     
- Misses       4674     5071     +397     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@drivanov drivanov requested a review from wsad1 as a code owner February 27, 2026 19:23
Copy link
Contributor

@puririshi98 puririshi98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm at a high level but please address these concerns:

  1. The retry logic was silently deleted without replacement. The original code had up to 200 inner retries and 5 outer retries. This was there for a reason — NIM API calls over the network fail transiently. The new code has zero retry logic. A single transient HTTP error in any worker will now raise a RuntimeError and abort the entire job. For expensive, long-running KG extraction jobs, this is a significant regression in robustness.

  2. _safe_worker swallows exceptions and returns a dict instead of raising. This is an anti-pattern with Pool.map. If a worker raises an exception, Pool.map will propagate it naturally to the main process — that's the correct behavior. The _safe_worker wrapper catches the exception, converts it to a dict, returns it as a "successful" result, and then the main process has to manually check every result for this sentinel value. This is more complex and fragile than just letting Pool.map propagate the exception. It also means if a worker silently returns a partial result before raising, it gets swallowed entirely.

  3. The chunk distribution has an off-by-one / data loss bug that was present before and is not fixed. meta_chunk_size = int(len(chunks) / num_procs) with integer division means if len(chunks) is not divisible by num_procs, the last few chunks are silently dropped. For example, 10 chunks across 3 workers: sizes are 3, 3, 3 — the 10th chunk is never processed. This was a pre-existing bug but this PR was the right opportunity to fix it (e.g. using np.array_split or adjusting the slicing).

  4. flat_triples.sort() sorts tuples lexicographically. This works, but the triples coming out of _parse_n_check_triples are lists, not tuples. Sorting lists also works, but the claim of "deterministic output" is only true within a single Python version and locale — list/tuple sort order is not guaranteed to be stable across Python versions for string content with mixed Unicode. Minor point, but worth noting for a library claiming reproducibility.

Aside from that please confirm you get an end 2 end run of txt2kg_rag on a small subsample using --use_x_percent_corpus

@drivanov
Copy link
Contributor Author

Done.
Yes, the L1_TXT2KG_RAG_GPU test with the --use_x_percent_corpus .003 parameter passes without problems.

Copy link
Contributor

@puririshi98 puririshi98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM just make the CI green and we can merge

@puririshi98 puririshi98 enabled auto-merge (squash) March 10, 2026 19:37
auto-merge was automatically disabled March 10, 2026 21:37

Head branch was pushed to by a user without write access

@drivanov
Copy link
Contributor Author

@akihironitta :
I'm not entirely sure, but it seems there are some issues with the code coverage analysis script.

I added at least 10 new tests today, but I still see the same missing coverage for 17 lines

Patch coverage is 73.01587% with 17 lines in your changes missing coverage

When I try to dig deeper and explore the links on that page, I see that

  • Commits have different number of coverage report uploads:
  • BASE commit is 174 commits behind HEAD on master
  • My latest commit is compared to code that is 11 months old.

 3. I also analyzed the Missed Lines of

  • torch_geometric/llm/models/llm.py
  • torch_geometric/llm/models/txt2kg.py
  • torch_geometric/llm/models/g_retriever.py

      and with ChatGPT's help, I created a set of tests for them. When I add pdb breakpoints at the appropriate places, I see that the program actually hits them (for instance, that one).
      However, the code coverage report still shows them as skipped, even though these new tests were actually executed:

      test/llm/models/test_llm.py::test_llm_prepare_inputs PASSED
      test/llm/models/test_llm.py::test_llm_single_prompt PASSED
      test/llm/models/test_llm.py::test_llm_variable_lengths PASSED 

      

@akihironitta
Copy link
Member

Thank you @drivanov for digging into what the issue is with codecov. I have seen this issue in the past, and it's likely due to their bug or our misconfiguration, so I'll merge this as is. Thank again for sending this patch!

@akihironitta akihironitta merged commit 2a120a6 into pyg-team:master Mar 13, 2026
18 of 19 checks passed
@drivanov drivanov deleted the txt2kg_sigterm branch March 18, 2026 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants