mystic_CBK commited on
Commit
755b529
·
1 Parent(s): eae3204

Improve OmegaConf patch: add robust patching with verification, patch both before and after fairseq-signals installation, and ensure module persistence

Browse files
Files changed (2) hide show
  1. Dockerfile +3 -0
  2. omegaconf_patch.py +21 -1
Dockerfile CHANGED
@@ -42,6 +42,9 @@ RUN git clone https://github.com/Jwoo5/fairseq-signals.git && \
42
  cd fairseq-signals && \
43
  pip install --editable ./
44
 
 
 
 
45
  # Copy application files
46
  COPY . .
47
 
 
42
  cd fairseq-signals && \
43
  pip install --editable ./
44
 
45
+ # Apply the patch again after fairseq-signals installation to ensure it persists
46
+ RUN python /app/omegaconf_patch.py
47
+
48
  # Copy application files
49
  COPY . .
50
 
omegaconf_patch.py CHANGED
@@ -5,7 +5,7 @@ This patch adds the missing is_primitive_type function to newer omegaconf versio
5
  """
6
 
7
  import omegaconf
8
- import types
9
 
10
  def patch_omegaconf():
11
  """Patch omegaconf to add missing is_primitive_type function."""
@@ -22,10 +22,30 @@ def patch_omegaconf():
22
 
23
  # Add the function to omegaconf._utils
24
  setattr(omegaconf._utils, 'is_primitive_type', is_primitive_type)
 
 
 
 
 
 
25
  print("Successfully patched OmegaConf with is_primitive_type function")
26
 
 
 
 
 
 
 
27
  except Exception as e:
28
  print(f"Warning: Could not patch OmegaConf: {e}")
 
 
 
 
 
 
 
 
29
 
30
  if __name__ == "__main__":
31
  patch_omegaconf()
 
5
  """
6
 
7
  import omegaconf
8
+ import sys
9
 
10
  def patch_omegaconf():
11
  """Patch omegaconf to add missing is_primitive_type function."""
 
22
 
23
  # Add the function to omegaconf._utils
24
  setattr(omegaconf._utils, 'is_primitive_type', is_primitive_type)
25
+
26
+ # Also patch the module in sys.modules to ensure it persists
27
+ if 'omegaconf._utils' in sys.modules:
28
+ utils_module = sys.modules['omegaconf._utils']
29
+ setattr(utils_module, 'is_primitive_type', is_primitive_type)
30
+
31
  print("Successfully patched OmegaConf with is_primitive_type function")
32
 
33
+ # Verify the patch worked
34
+ if hasattr(omegaconf._utils, 'is_primitive_type'):
35
+ print("Patch verification successful: is_primitive_type is now available")
36
+ else:
37
+ print("WARNING: Patch verification failed!")
38
+
39
  except Exception as e:
40
  print(f"Warning: Could not patch OmegaConf: {e}")
41
+ # Try alternative patching method
42
+ try:
43
+ print("Trying alternative patching method...")
44
+ import omegaconf._utils as utils
45
+ setattr(utils, 'is_primitive_type', lambda obj: obj is None or isinstance(obj, (bool, int, float, str)))
46
+ print("Alternative patching successful")
47
+ except Exception as e2:
48
+ print(f"Alternative patching also failed: {e2}")
49
 
50
  if __name__ == "__main__":
51
  patch_omegaconf()