Spaces:
Sleeping
Sleeping
Add rouge-score/anthropic/openai; make deepspeed import optional
Browse files- model/dist_funs.py +12 -5
- requirements.txt +5 -0
model/dist_funs.py
CHANGED
|
@@ -6,7 +6,12 @@ from lavis.common.dist_utils import is_dist_avail_and_initialized
|
|
| 6 |
from model.help_funcs import pad_and_concat
|
| 7 |
from pytorch_lightning import strategies
|
| 8 |
from lightning_fabric.utilities.types import _PATH
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
|
| 12 |
'''
|
|
@@ -20,7 +25,7 @@ def module_state_dict(self, destination=None, prefix="", keep_vars=False, exclud
|
|
| 20 |
if exclude_frozen_parameters:
|
| 21 |
to_be_removed = []
|
| 22 |
for n in sd:
|
| 23 |
-
try:
|
| 24 |
if not self.module.get_parameter(n).requires_grad:
|
| 25 |
to_be_removed.append(n)
|
| 26 |
except AttributeError:
|
|
@@ -30,11 +35,13 @@ def module_state_dict(self, destination=None, prefix="", keep_vars=False, exclud
|
|
| 30 |
if self.random_ltd_enabled():
|
| 31 |
sd = remove_random_ltd_state_dict(sd)
|
| 32 |
return sd
|
| 33 |
-
|
| 34 |
-
DeepSpeedEngine.module_state_dict = module_state_dict
|
| 35 |
### end overwrite ###
|
| 36 |
|
| 37 |
-
|
|
|
|
|
|
|
| 38 |
def save_checkpoint_v1(
|
| 39 |
self, checkpoint: Dict[str, Any], filepath: _PATH, storage_options: Optional[Any] = None
|
| 40 |
):
|
|
|
|
| 6 |
from model.help_funcs import pad_and_concat
|
| 7 |
from pytorch_lightning import strategies
|
| 8 |
from lightning_fabric.utilities.types import _PATH
|
| 9 |
+
try:
|
| 10 |
+
from deepspeed.runtime.data_pipeline.data_routing.helper import remove_random_ltd_state_dict
|
| 11 |
+
from deepspeed import DeepSpeedEngine
|
| 12 |
+
_DEEPSPEED_AVAILABLE = True
|
| 13 |
+
except ImportError:
|
| 14 |
+
_DEEPSPEED_AVAILABLE = False
|
| 15 |
|
| 16 |
|
| 17 |
'''
|
|
|
|
| 25 |
if exclude_frozen_parameters:
|
| 26 |
to_be_removed = []
|
| 27 |
for n in sd:
|
| 28 |
+
try:
|
| 29 |
if not self.module.get_parameter(n).requires_grad:
|
| 30 |
to_be_removed.append(n)
|
| 31 |
except AttributeError:
|
|
|
|
| 35 |
if self.random_ltd_enabled():
|
| 36 |
sd = remove_random_ltd_state_dict(sd)
|
| 37 |
return sd
|
| 38 |
+
if _DEEPSPEED_AVAILABLE:
|
| 39 |
+
DeepSpeedEngine.module_state_dict = module_state_dict
|
| 40 |
### end overwrite ###
|
| 41 |
|
| 42 |
+
_DeepSpeedStrategyBase = strategies.DeepSpeedStrategy if _DEEPSPEED_AVAILABLE else object
|
| 43 |
+
|
| 44 |
+
class MyDeepSpeedStrategy(_DeepSpeedStrategyBase):
|
| 45 |
def save_checkpoint_v1(
|
| 46 |
self, checkpoint: Dict[str, Any], filepath: _PATH, storage_options: Optional[Any] = None
|
| 47 |
):
|
requirements.txt
CHANGED
|
@@ -48,6 +48,11 @@ regex==2024.11.6
|
|
| 48 |
web.py==0.62
|
| 49 |
cheroot==10.0.1
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
# spacy's runtime deps (spacy itself is installed --no-deps in the Dockerfile
|
| 52 |
# because its typer<0.10 pin conflicts with gradio's typer>=0.12)
|
| 53 |
catalogue==2.0.10
|
|
|
|
| 48 |
web.py==0.62
|
| 49 |
cheroot==10.0.1
|
| 50 |
|
| 51 |
+
# other runtime deps imported by model/ and evals/
|
| 52 |
+
rouge-score==0.1.2
|
| 53 |
+
anthropic==0.40.0
|
| 54 |
+
openai==2.7.2
|
| 55 |
+
|
| 56 |
# spacy's runtime deps (spacy itself is installed --no-deps in the Dockerfile
|
| 57 |
# because its typer<0.10 pin conflicts with gradio's typer>=0.12)
|
| 58 |
catalogue==2.0.10
|