perf(utils): EojeolCounter 멀티프로세싱 지원 - #169
Merged
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>
lovit
commented
Mar 8, 2026
lovit
left a comment
Owner
Author
There was a problem hiding this comment.
리뷰 결과: 수정 완료
발견된 이슈:
_count_eojeol_chunk워커가preprocess인자를 받지 않아, picklable한 custom preprocess 함수도 항상 단일 프로세스로 fallback됨- PR #170 (PredicatorExtractor)에서
normalize_sent_for_lrgraph(module-level, picklable)를 preprocess로 전달하는데, 이 경우도 병렬화가 되지 않는 문제
수정 내용 (d233203):
_count_eojeol_chunk: 4번째preprocess인자 추가EojeolCounter.__init__:_parallel_preprocess속성 추가 (pickle 가능 여부 검사)_counting_from_sents: picklable custom preprocess도 병렬 처리하도록 dispatch 로직 수정_counting_from_sents_parallel:preprocess파라미터 추가
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 #162
EojeolCounter._counting_from_sents()에 멀티프로세싱 지원을 추가합니다.이 클래스는
LRNounExtractor,PredicatorExtractor등이 공통으로 사용하는 집계 인프라로, 여기서 병렬화하면 하위 extractor들이 모두 혜택을 받습니다.변경 내용
soynlp/utils/utils.py_count_eojeol_chunk(): 모듈 레벨 worker 함수 추가 (pickling 가능)EojeolCounter.__init__:n_workers=1파라미터 추가_counting_from_sents():n_workers인자 수신 후 parallel/sequential 분기_counting_from_sents_parallel():multiprocessing.Pool로 청크별 병렬 집계 후 결과 병합n_workers=-1→cpu_count()자동 사용preprocess사용 시 단일 프로세스 폴백 (로그 경고)tests/unit/test_utils.pytest_eojeol_counter_multi_equals_single(): n_workers=4 결과 == n_workers=1 결과test_eojeol_counter_auto_workers(): n_workers=-1 동작 검증test_eojeol_counter_multi_with_min_count(): min_count 필터 + 멀티프로세싱 동작하위 호환성
n_workers=1(기본값) 시 기존 단일 프로세스 경로와 동일하게 동작의존 관계