Skip to content

perf(utils): EojeolCounter 멀티프로세싱 지원 - #169

Merged
lovit merged 3 commits into
refactor-2026from
feature/162
Mar 9, 2026
Merged

perf(utils): EojeolCounter 멀티프로세싱 지원#169
lovit merged 3 commits into
refactor-2026from
feature/162

Conversation

@lovit

@lovit lovit commented Mar 8, 2026

Copy link
Copy Markdown
Owner

개요

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=-1cpu_count() 자동 사용
    • custom preprocess 사용 시 단일 프로세스 폴백 (로그 경고)

tests/unit/test_utils.py

  • test_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 (기본값) 시 기존 단일 프로세스 경로와 동일하게 동작
  • 기존 API 변경 없음

의존 관계

lovit and others added 3 commits March 9, 2026 05:41
- 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 lovit left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

리뷰 결과: 수정 완료

발견된 이슈:

  • _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 파라미터 추가

@lovit
lovit merged commit c278612 into refactor-2026 Mar 9, 2026
2 checks passed
@lovit
lovit deleted the feature/162 branch March 9, 2026 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant