Skip to content
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

Resolve most skipped unittests #559

Merged
merged 30 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
20b1ffe
* fix missing attribute error and duplicate test funcs
HYLcool Dec 24, 2024
c57ca12
* fix unexpected keyword argument error
HYLcool Dec 24, 2024
38bfd06
* review for OOM tests
HYLcool Dec 25, 2024
8fb34b3
* review for OOM tests
HYLcool Dec 25, 2024
f63a80e
- use 2 np instead of 4 np for unittest
HYLcool Dec 25, 2024
8a4e822
- use 2 np instead of 4 np for unittest to resolve OOM problem
HYLcool Dec 25, 2024
13460e5
* update doc of analyzer
HYLcool Dec 26, 2024
4110a1a
* fix undefined device_map: using balanced in default or use `to` met…
HYLcool Dec 27, 2024
829a0c7
* fix bugs in video_captioning_from_summarizer_mapper due to reorgani…
HYLcool Dec 27, 2024
3aee531
- remove unused imports
HYLcool Dec 27, 2024
4805928
* open unittest for nlpcda_en_mapper
HYLcool Dec 30, 2024
6020a41
* set the default encoding of stdout to utf-8
HYLcool Dec 30, 2024
d464b79
* set the default encoding of stdout to utf-8
HYLcool Dec 30, 2024
8981b63
* set the default encoding of stdout to utf-8
HYLcool Dec 30, 2024
2025a2e
* test for raft
HYLcool Dec 30, 2024
85e757d
* change the thresholds
HYLcool Dec 30, 2024
b41833e
+ add mem_required for generate_qa_from_text_mapper
HYLcool Jan 9, 2025
fb503db
+ add mem_required for two ops
HYLcool Jan 13, 2025
1aa9d24
Merge branch 'main' into resolve/unittest_skipping
HYLcool Jan 14, 2025
432de0f
- open unittest for generate_qa_from_text_mapper
HYLcool Jan 15, 2025
06267ba
- open unittest for generate_qa_from_examples_mapper
HYLcool Jan 15, 2025
c56a629
Merge branch 'main' into resolve/unittest_skipping
HYLcool Jan 15, 2025
684666e
Merge branch 'main' into resolve/unittest_skipping
HYLcool Jan 20, 2025
bece0d1
* fix skip_op_error & update_sampling_params
HYLcool Jan 20, 2025
88e9aa4
* update vllm version requirement for generation_config param
HYLcool Jan 20, 2025
26d0f84
* skip vllm ops
HYLcool Jan 20, 2025
6874191
* open unittests for api-related ops
HYLcool Jan 21, 2025
42e54bc
Merge branch 'main' into resolve/unittest_skipping
HYLcool Jan 21, 2025
f52106d
* fix wrong attr name
HYLcool Jan 21, 2025
d2b0064
* increase shm_size to avoid OOM
HYLcool Jan 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
ports:
- "6379:6379"
- "8265:8265"
shm_size: "64G"
shm_size: "128G"
deploy:
resources:
reservations:
Expand Down Expand Up @@ -49,7 +49,7 @@ services:
- ray-head
networks:
- ray-network
shm_size: "64G"
shm_size: "128G"
deploy:
resources:
reservations:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
- name: Run unittest standalone
working-directory: dj-${{ github.run_id }}/.github/workflows/docker
run: |
docker compose exec ray-head python tests/run.py --tag standalone
docker compose exec -e OPENAI_BASE_URL=${{ secrets.OPENAI_BASE_URL }} -e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} ray-head python tests/run.py --tag standalone

- name: Run unittest ray
working-directory: dj-${{ github.run_id }}/.github/workflows/docker
Expand Down
37 changes: 20 additions & 17 deletions configs/config_all.yaml

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion data_juicer/core/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ def __init__(self, cfg: dict):
self.cfg = cfg

# insight mining related
self.enable_insight_mining = self.cfg.open_insight_mining
self.enable_insight_mining = self.cfg.open_insight_mining if hasattr(
self.cfg, 'open_insight_mining') else False

# resource probe related
self.idle_resources = Monitor.monitor_current_resources()
Expand Down
4 changes: 2 additions & 2 deletions data_juicer/core/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def run(self,
f'[{self.cfg.fusion_strategy}]...')
ops = fuse_operators(ops, probe_res)

# 2. stats precompute only for filter ops
# 2. stats precompute only for filter or tagging ops
logger.info('Computing the stats of dataset...')
stats_collected = False
for op in ops:
Expand Down Expand Up @@ -147,7 +147,7 @@ def run(self,
compress(dataset)

# 4. analysis and output result to the export path
# 4.1. Only consider fields in Fields.stats
# 4.1. Only consider fields in Fields.stats and Fields.meta
# 4.2. For string fields, only consider its histogram
# 4.3. For numeric fields, consider its histogram and box
# 4.4. Otherwise, DO NOT analyze
Expand Down
2 changes: 1 addition & 1 deletion data_juicer/ops/base_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def wrapper(sample, *args, **kwargs):
else:
return [res]
except Exception as e:
if skip_op_error:
if not skip_op_error:
raise
from loguru import logger
logger.error(f'An error occurred in {op_name} when processing '
Expand Down
7 changes: 3 additions & 4 deletions data_juicer/ops/mapper/generate_qa_from_examples_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ def __init__(self,
model_params = model_params or {}
sampling_params = sampling_params or {}

sampling_params = update_sampling_params(sampling_params, hf_model,
self.enable_vllm)

if enable_vllm:
assert torch.cuda.device_count() >= 1, 'must be executed in CUDA'
# cannot initialize vllm replicas on different GPUs
Expand All @@ -140,10 +143,6 @@ def __init__(self,
**model_params)
self.sampling_params = sampling_params

self.sampling_params = update_sampling_params(sampling_params,
hf_model,
self.enable_vllm)

self.seed_qa_samples = self._load_seed_qa_samples()
if len(self.seed_qa_samples) == 0:
raise ValueError('No QA data was parsed from the seed file!')
Expand Down
7 changes: 3 additions & 4 deletions data_juicer/ops/mapper/generate_qa_from_text_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def __init__(self,
model_params = model_params or {}
sampling_params = sampling_params or {}

sampling_params = update_sampling_params(sampling_params, hf_model,
self.enable_vllm)

if enable_vllm:
assert torch.cuda.device_count() >= 1, 'must be executed in CUDA'
# cannot initialize vllm replicas on different GPUs
Expand All @@ -107,10 +110,6 @@ def __init__(self,
**model_params)
self.sampling_params = sampling_params

self.sampling_params = update_sampling_params(sampling_params,
hf_model,
self.enable_vllm)

def parse_output(self, raw_output):
logger.debug(raw_output)
qa_list = []
Expand Down
7 changes: 3 additions & 4 deletions data_juicer/ops/mapper/optimize_qa_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def __init__(self,
model_params = model_params or {}
sampling_params = sampling_params or {}

sampling_params = update_sampling_params(sampling_params, hf_model,
self.enable_vllm)

if enable_vllm:
assert torch.cuda.device_count() >= 1, 'must be executed in CUDA'
# cannot initialize vllm replicas on different GPUs
Expand All @@ -99,10 +102,6 @@ def __init__(self,
**model_params)
self.sampling_params = sampling_params

self.sampling_params = update_sampling_params(sampling_params,
hf_model,
self.enable_vllm)

def build_input(self, sample):
qa_pair = self.qa_pair_template.format(sample[self.query_key],
sample[self.response_key])
Expand Down
16 changes: 14 additions & 2 deletions data_juicer/utils/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@
'FastSAM-x.pt',
}

TORCH_DTYPE_MAPPING = {
'fp32': torch.float32,
'fp16': torch.float16,
'bf16': torch.bfloat16,
}


def get_backup_model_link(model_name):
for pattern, url in BACKUP_MODEL_LINKS.items():
Expand Down Expand Up @@ -291,8 +297,12 @@ def prepare_diffusion_model(pretrained_model_name_or_path, diffusion_type,
"""
AUTOINSTALL.check(['torch', 'transformers'])

if 'device' in model_params:
model_params['device_map'] = model_params.pop('device')
device = model_params.pop('device', None)
if not device:
model_params['device_map'] = 'balanced'
if 'torch_dtype' in model_params:
model_params['torch_dtype'] = TORCH_DTYPE_MAPPING[
model_params['torch_dtype']]

diffusion_type_to_pipeline = {
'image2image': diffusers.AutoPipelineForImage2Image,
Expand All @@ -309,6 +319,8 @@ def prepare_diffusion_model(pretrained_model_name_or_path, diffusion_type,
pipeline = diffusion_type_to_pipeline[diffusion_type]
model = pipeline.from_pretrained(pretrained_model_name_or_path,
**model_params)
if device:
model = model.to(device)

return model

Expand Down
2 changes: 1 addition & 1 deletion environments/science_requires.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ simple-aesthetics-predictor
scenedetect[opencv]
ffmpeg-python
opencv-python
vllm>=0.1.3
vllm>=0.6.5
rouge
dashscope
openai
Expand Down
5 changes: 2 additions & 3 deletions tests/ops/aggregator/test_entity_attribute_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.aggregator import EntityAttributeAggregator
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase, SKIPPED_TESTS
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, BatchMetaKeys, MetaKeys


@SKIPPED_TESTS.register_module()
class EntityAttributeAggregatorTest(DataJuicerTestCaseBase):

def _run_helper(self, op, samples, output_key=BatchMetaKeys.entity_attribute):
Expand All @@ -24,7 +23,7 @@ def _run_helper(self, op, samples, output_key=BatchMetaKeys.entity_attribute):
for k in data:
logger.info(f"{k}: {data[k]}")
self.assertIn(output_key, data[Fields.batch_meta])
self.assertNotEqual(data[Fields.batch_met][output_key], '')
self.assertNotEqual(data[Fields.batch_meta][output_key], '')

self.assertEqual(len(new_dataset), len(samples))

Expand Down
4 changes: 1 addition & 3 deletions tests/ops/aggregator/test_meta_tags_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.aggregator import MetaTagsAggregator
from data_juicer.utils.constant import Fields, MetaKeys
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase, SKIPPED_TESTS
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase


@SKIPPED_TESTS.register_module()
class MetaTagsAggregatorTest(DataJuicerTestCaseBase):

def _run_helper(self, op, samples):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.aggregator import MostRelavantEntitiesAggregator
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase, SKIPPED_TESTS
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase

from data_juicer.utils.constant import Fields, BatchMetaKeys, MetaKeys


@SKIPPED_TESTS.register_module()
class MostRelavantEntitiesAggregatorTest(DataJuicerTestCaseBase):

def _run_helper(self, op, samples, output_key=BatchMetaKeys.most_relavant_entities):
Expand Down
4 changes: 1 addition & 3 deletions tests/ops/aggregator/test_nested_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.aggregator import NestedAggregator
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase, SKIPPED_TESTS
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase

from data_juicer.utils.constant import Fields, MetaKeys


@SKIPPED_TESTS.register_module()
class NestedAggregatorTest(DataJuicerTestCaseBase):

def _run_helper(self, op, samples, output_key=MetaKeys.event_description):
Expand Down
14 changes: 5 additions & 9 deletions tests/ops/filter/test_video_motion_score_raft_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@
from data_juicer.ops.filter.video_motion_score_raft_filter import \
VideoMotionScoreRaftFilter
from data_juicer.utils.constant import Fields
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase, SKIPPED_TESTS

# skip due to conflicts when run lazy_load in multiprocessing in librosa
# tests passed locally.
@SKIPPED_TESTS.register_module()
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
class VideoMotionScoreRaftFilterTest(DataJuicerTestCaseBase):

data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), '..',
Expand Down Expand Up @@ -133,7 +129,7 @@ def test_middle(self):
'videos': [self.vid3_path]
}]
tgt_list = [{'videos': [self.vid2_path]}]
op = VideoMotionScoreRaftFilter(min_score=3, max_score=10.5)
op = VideoMotionScoreRaftFilter(min_score=3, max_score=10.2)
self._run_helper(op, ds_list, tgt_list)

def test_any(self):
Expand All @@ -150,7 +146,7 @@ def test_any(self):
'videos': [self.vid2_path, self.vid3_path]
}]
op = VideoMotionScoreRaftFilter(min_score=3,
max_score=10.5,
max_score=10.2,
any_or_all='any')
self._run_helper(op, ds_list, tgt_list)

Expand All @@ -164,7 +160,7 @@ def test_all(self):
}]
tgt_list = []
op = VideoMotionScoreRaftFilter(min_score=3,
max_score=10.5,
max_score=10.2,
any_or_all='all')
self._run_helper(op, ds_list, tgt_list)

Expand All @@ -180,7 +176,7 @@ def test_parallel(self):
'videos': [self.vid3_path]
}]
tgt_list = [{'videos': [self.vid2_path]}]
op = VideoMotionScoreRaftFilter(min_score=3, max_score=10.5)
op = VideoMotionScoreRaftFilter(min_score=3, max_score=10.2)
self._run_helper(op, ds_list, tgt_list, np=2)


Expand Down
28 changes: 1 addition & 27 deletions tests/ops/mapper/test_calibrate_qa_mapper.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import os
import unittest
from unittest.mock import Mock, patch

import httpx
from loguru import logger

from data_juicer.ops.mapper.calibrate_qa_mapper import CalibrateQAMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase


# Skip tests for this OP because the API call is not configured yet.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class CalibrateQAMapperTest(DataJuicerTestCaseBase):

def _run_op(self, op):
Expand Down Expand Up @@ -81,23 +73,5 @@ def test_args(self):
response_path='choices.0.message.content')
self._run_op(op)

@patch('httpx.Client.send')
def test_retry(self, mock_send):
mock_response = Mock()
mock_response.status_code = 408
mock_response.headers = {}
mock_request = Mock()
mock_response.raise_for_status.side_effect = httpx.HTTPStatusError(
'408 Client Error: Request Timeout',
request=mock_request,
response=mock_response)
mock_send.return_value = mock_response

with self.assertLogs(level='DEBUG') as cm:
op = CalibrateQAMapper(api_model='test',
model_params={'max_retries': 3})
op.process({'text': '', 'query': '', 'response': ''})
self.assertIn('3 retries left', '\n'.join(cm.output))

if __name__ == '__main__':
unittest.main()
7 changes: 1 addition & 6 deletions tests/ops/mapper/test_calibrate_query_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,8 @@
from loguru import logger

from data_juicer.ops.mapper.calibrate_query_mapper import CalibrateQueryMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase


# Skip tests for this OP because the API call is not configured yet.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class CalibrateQueryMapperTest(DataJuicerTestCaseBase):

def _run_op(self, api_model, response_path=None):
Expand Down
6 changes: 1 addition & 5 deletions tests/ops/mapper/test_calibrate_response_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

from data_juicer.ops.mapper.calibrate_response_mapper import \
CalibrateResponseMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase


# Skip tests for this OP because the API call is not configured yet.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class CalibrateResponseMapperTest(DataJuicerTestCaseBase):

def _run_op(self, api_model, response_path=None):
Expand Down
6 changes: 1 addition & 5 deletions tests/ops/mapper/test_dialog_intent_detection_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.dialog_intent_detection_mapper import DialogIntentDetectionMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class TestDialogIntentDetectionMapper(DataJuicerTestCaseBase):
# before runing this test, set below environment variables:
# export OPENAI_API_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
Expand Down
6 changes: 1 addition & 5 deletions tests/ops/mapper/test_dialog_sentiment_detection_mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@

from data_juicer.core.data import NestedDataset as Dataset
from data_juicer.ops.mapper.dialog_sentiment_detection_mapper import DialogSentimentDetectionMapper
from data_juicer.utils.unittest_utils import (SKIPPED_TESTS,
DataJuicerTestCaseBase)
from data_juicer.utils.unittest_utils import DataJuicerTestCaseBase
from data_juicer.utils.constant import Fields, MetaKeys

# Skip tests for this OP.
# These tests have been tested locally.
@SKIPPED_TESTS.register_module()
class TestDialogSentimentDetectionMapper(DataJuicerTestCaseBase):
# before runing this test, set below environment variables:
# export OPENAI_API_URL=https://dashscope.aliyuncs.com/compatible-mode/v1
Expand Down
Loading
Loading