Repository: microsoft/DeepSpeed

Issue:
[BUG] No module named 'fcntl' while importing the package
Hey,
Working on windows 11, Python 3.7 and tried importing the package.
Got the error in the title, is there a way around it since it's exclusive to Linux?

![fcntl](https://user-images.githubusercontent.com/61480454/164317686-5303f264-5fc7-42c0-89b5-d16a125ae11f.png)
 


Discussion:
It seems that the `fcntl` module is only used for debug purposes. We should probably disable these imports and only enable them when debugging. You can safely remove this import. Here is a patch that does that for the current master (`32d97976ce08f00228ceb55a2d93005bd8b2769a`):
```
diff --git a/deepspeed/runtime/zero/partition_parameters.py b/deepspeed/runtime/zero/partition_parameters.py
index 5c3b67bd..8c662f71 100755
--- a/deepspeed/runtime/zero/partition_parameters.py
+++ b/deepspeed/runtime/zero/partition_parameters.py
@@ -26,7 +26,7 @@ from .offload_constants import *
 from ..utils import get_only_unique_item, see_memory_usage
 from deepspeed.runtime.zero.utils import assert_ints_same_as_other_ranks
 from deepspeed.utils import init_distributed, instrument_w_nvtx, logger
-from deepspeed.utils.debug import debug_param2name_id_shape, debug_param2name_id_shape_device, debug_module2name, debug_param2name, debug_param2name_id_shape_status, printflock, log_rank_file
+from deepspeed.utils.debug import debug_param2name_id_shape, debug_param2name_id_shape_device, debug_module2name, debug_param2name, debug_param2name_id_shape_status, log_rank_file#, printflock
 from deepspeed.utils.logging import logger
 
 from ..swap_tensor.partitioned_param_swapper import AsyncPartitionedParameterSwapper, PartitionedParamStatus
diff --git a/deepspeed/runtime/zero/stage3.py b/deepspeed/runtime/zero/stage3.py
index 0bd505ca..32eedddd 100755
--- a/deepspeed/runtime/zero/stage3.py
+++ b/deepspeed/runtime/zero/stage3.py
@@ -41,7 +41,7 @@ from deepspeed.checkpoint.constants import OPTIMIZER_STATE_DICT, FP32_FLAT_GROUP
 pg_correctness_test = False
 
 FWD_MODULE_STACK = list()
-from deepspeed.utils.debug import debug_module2name_id, debug_param2name_id, debug_param2name_id_numel, debug_param2name_id_shape_device, debug_module2name_class, printflock, log_rank_file
+from deepspeed.utils.debug import debug_module2name_id, debug_param2name_id, debug_param2name_id_numel, debug_param2name_id_shape_device, debug_module2name_class, log_rank_file#, printflock
 
 
 def print_rank_0(message, debug=False, force=False):
diff --git a/deepspeed/utils/debug.py b/deepspeed/utils/debug.py
index 358e997e..17c21e40 100644
--- a/deepspeed/utils/debug.py
+++ b/deepspeed/utils/debug.py
@@ -1,6 +1,6 @@
 """ debug utils """
 
-import fcntl
+#import fcntl
 
 # for debug purposes map module and param objects to their fully qualified names
 module_names = {}
@@ -58,6 +58,7 @@ def debug_param2name_id_shape_status(param):
     return f"name={debug_param2name(param)} id={param.ds_id} shape={param.data.shape} status={param.ds_status}"
 
 
+'''
 def printflock(*msgs):
     """
 
@@ -85,7 +86,7 @@ def printflock(*msgs):
             print(*msgs)
         finally:
             fcntl.flock(fh, fcntl.LOCK_UN)
-
+'''
 
 fh = None
 
```

To use this:
1. `git clone https://github.com/microsoft/DeepSpeed.git && cd DeepSpeed`
2. save the patch as `no-fcntl.patch` in the DeepSpeed repo
3. `git apply no-fcntl.patch`
4. Install this modified DeepSpeed with `pip install .`
Thanks!
When will it be updated, as in without a patch...


Resolving patch:
diff --git a/deepspeed/utils/debug.py b/deepspeed/utils/debug.py
--- a/deepspeed/utils/debug.py
+++ b/deepspeed/utils/debug.py
@@ -1,6 +1,7 @@
 """ debug utils """
 
-import fcntl
+# For lazy import with printflock()
+fcntl = None
 
 # for debug purposes map module and param objects to their fully qualified names
 module_names = {}
@@ -78,6 +79,9 @@ def print_rank_0(message, debug=False, force=False):
     then compare those.
 
     """
+    global fcntl
+    if fcntl == None:
+        import fcntl
 
     with open(__file__, "r") as fh:
         fcntl.flock(fh, fcntl.LOCK_EX)


Test patch: