perf(predicator): PredicatorExtractor 멀티프로세싱 지원 - #170
Merged
Conversation
- EojeolCounter.__init__에 n_workers 파라미터 추가 (기본값 1) - _count_eojeol_chunk(): 모듈 레벨 worker 함수 (pickle 가능) - _counting_from_sents_parallel(): multiprocessing.Pool로 청크별 병렬 집계 후 병합 - custom preprocess 사용 시 n_workers 무시하고 단일 프로세스 폴백 - n_workers=-1이면 cpu_count() 자동 사용 - 테스트 3개 추가: 멀티/단일 결과 동일성, auto workers, min_count 필터 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
함수명에 의존하는 취약한 체크 방식을 _has_custom_preprocess 플래그로 대체 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- _count_eojeol_chunk(): preprocess 인자(4번째) 추가 - EojeolCounter.__init__: _parallel_preprocess 속성 추가 (pickle 가능 여부 검사) - _counting_from_sents(): picklable custom preprocess도 병렬 처리 가능하도록 dispatch 로직 수정 - _counting_from_sents_parallel(): preprocess 파라미터 추가 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
EojeolCounter의 n_workers 지원(#162)을 활용하여 PredicatorExtractor에 멀티프로세싱을 추가. 아울러 EojeolCounter를 picklable 함수를 병렬 경로에서도 활용할 수 있도록 개선. - utils/utils.py - _count_eojeol_chunk(): preprocess 인자 추가 (None이면 무적용) - _parallel_preprocess 속성으로 pickle 가능 여부 판단 - _counting_from_sents_parallel(): preprocess 파라미터 전달 지원 - predicator/predicator.py - train_extract(), train(), _train_with_sentences()에 n_workers=1 파라미터 추가 - EojeolCounter 생성 시 n_workers pass-through - tests/unit/test_predicator.py - n_workers=4 수용 테스트 - 멀티/단일 EojeolCounter 결과 동일성 테스트 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
feature/162 rebase 시 conflict 해결 과정에서 EojeolCounter.__init__의 _has_custom_preprocess 초기화 라인이 빠짐. _counting_from_sents에서 해당 속성 참조 시 AttributeError 발생하던 문제 수정. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
lovit
commented
Mar 8, 2026
lovit
left a comment
Owner
Author
There was a problem hiding this comment.
리뷰 결과: 수정 완료
발견된 이슈:
_counting_from_sents에서self.preprocess.__name__ == "base_preprocessing"방식은 취약 — 사용자가 동일한 이름의 함수를 정의하거나, Python 내부적으로 이름이 바뀔 경우 잘못 동작할 수 있음utils.py가 PR #169와 충돌 — feature/162의 구현이 변경되면 두 PR이 같은 라인을 다르게 수정함
수정 내용:
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
개요
Closes #163
PredicatorExtractor.train()에n_workers파라미터를 추가하고,EojeolCounter집계 단계를 병렬화합니다.의존 관계
변경 내용
soynlp/utils/utils.py_count_eojeol_chunk():preprocess인자 추가 — module-level 함수이면 worker에서 직접 적용EojeolCounter.__init__:_parallel_preprocess속성 도입 — pickle 가능 여부 자동 판단_counting_from_sents(): pickle 가능한 custom preprocess도 병렬 경로 허용_counting_from_sents_parallel():preprocess파라미터 전달soynlp/predicator/predicator.pytrain_extract(),train(),_train_with_sentences()에n_workers=1파라미터 추가EojeolCounter생성 시n_workerspass-throughensure_normalized=False(기본값) 시normalize_sent_for_lrgraph(module-level 함수)가 worker에서 실행됨ensure_normalized=True시 lambda 사용 → pickle 불가 → 단일 프로세스 폴백tests/unit/test_predicator.pyTestPredicatorExtractorMultiprocessing클래스 추가n_workers=4수용 테스트EojeolCounter결과 동일성 검증