masashi-y / depccg

A* CCG Parser with a Supertag and Dependency Factored Model
MIT License
91 stars 28 forks source link

How to specify GPU usage in A* parsing #26

Closed MinionAttack closed 3 years ago

MinionAttack commented 3 years ago

Hi,

I'm using a project that uses EnglishCCGParser (v1) (depccg 1.0.8):

def __init__(self):
        kwargs = dict(
            # A list of binary rules 
            # By default: depccg.combinator.en_default_binary_rules
            binary_rules=None,
            # Penalize an application of a unary rule by adding this value (negative log probability)
            unary_penalty=0.1,
            # Prune supertags with low probabilities using this value
            beta=0.00001,
            # Set False if not prune
            use_beta=True,
            # Use category dictionary
            use_category_dict=True,
            # Use seen rules
            use_seen_rules=True,
            # This also used to prune supertags
            pruning_size=50,
            # Nbest outputs
            nbest=1,
            # Limit categories that can appear at the root of a CCG tree
            # By default: S[dcl], S[wq], S[q], S[qem], NP.
            possible_root_cats=None,
            # Give up parsing long sentences
            max_length=250,
            # Give up parsing if it runs too many steps
            max_steps=100000,
            # You can specify a GPU
            gpu=0
        )
        self.model = EnglishCCGParser.from_dir(DEPCCG_MODEL_FILENAME, load_tagger=True, **kwargs)

And the console output is:

2021-09-15 16:16:22,209 - INFO - depccg.parser - start tagging sentences
2021-09-15 17:00:07,350 - INFO - depccg.parser - done tagging sentences
2021-09-15 17:00:07,375 - INFO - depccg.parser - unary penalty = 0.1
2021-09-15 17:00:07,375 - INFO - depccg.parser - beta value = 1e-05 (use beta = True)
2021-09-15 17:00:07,375 - INFO - depccg.parser - pruning size = 50
2021-09-15 17:00:07,376 - INFO - depccg.parser - N best = 1
2021-09-15 17:00:07,376 - INFO - depccg.parser - use category dictionary = True
2021-09-15 17:00:07,376 - INFO - depccg.parser - use seen rules = True
2021-09-15 17:00:07,376 - INFO - depccg.parser - allow at the root of a tree only categories in [S[dcl], S[wq], S[q], S[qem], NP]
2021-09-15 17:00:07,376 - INFO - depccg.parser - give up sentences that contain > 250 words
2021-09-15 17:00:07,376 - INFO - depccg.parser - combinators: [>, <, >B1, <B1, >B2, <B2, <Φ>, <Φ>, <rp>, <rp>, <rp>, <*>, <*>]
2021-09-15 17:00:09,437 - INFO - depccg.parser - start A* parsing

I'm trying to parse 600K sentences, looking at the system monitor it's using the CPU instead of the GPU and the code has been running for 4 days. I can't see the progress or anything.

I run the code via Intellij Idea and in the environment variables I have specified:

PYTHONUNBUFFERED=1;CUDA_VISIBLE_DEVICES=1.

When tagging I can see that uses the GPU but when it starts with the A* parsing it uses CPU instead.

How long does it take to parse that many sentences or how can I force GPU usage?

Regards.

masashi-y commented 3 years ago

Hello, thank you for using depccg for your project, and I'm sorry for the inconvenience. Actually, the parser does not perform any heavy score calculation when doing A parsing (it searches for a tree using scores computed at the tagging phase), so the entire pipeline seems to be working as I expected. The problem is that the C++ A algorithm written by me is a bit unstable and gets stuck sometimes, especially when parsing many sentences at one time. I hopefully fixed the problem in the newer version of depccg (v2), so could you please try using it?

MinionAttack commented 3 years ago

Hi, I have tried to upgrade to the latest version but the problem is that the base project I am using is a bit old so the upgrade from 1.0.8 to 2.0.2 changes a lot of dependencies and the base project stops working properly.

So I decided to modify the code of the base project and instead of trying to parse all 600K sentences at once, I parse them one by one and with the help of TQDM I can see that parsing them all takes about 25 hours.

Since I don't need to do the parsing many times it's not a big problem for me.

Regards.